小丸子學Docker系列之——安裝Docker及基本命令的使用
環境要求:在Centos7.x上安裝docker官方要求核心至少是3.10
1.檢視核心和作業系統版本
[root@docker-machine ~]# uname -r
3.10.0-327.el7.x86_64
[root@docker-machine ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
2.yum方式安裝——docker安裝提供了兩種方式,一種是yum,一種是透過scripts安裝,這裡我們選擇前者
[root@docker-machine ~]# yum update
3.新增yum repo
[root@docker-machine ~]# tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=
enabled=1
gpgcheck=1
gpgkey=
EOF
4.安裝docker
[root@docker-machine ~]# yum install docker-engine
=================================================================================================
Package Arch Version Repository Size
=================================================================================================
Installing:
docker-engine x86_64 1.9.1-1.el7.centos dockerrepo 8.2 M
Installing for dependencies:
audit-libs-python x86_64 2.4.1-5.el7 base 69 k
checkpolicy x86_64 2.1.12-6.el7 base 247 k
docker-engine-selinux noarch 1.9.1-1.el7.centos dockerrepo 21 k
libcgroup x86_64 0.41-8.el7 base 64 k
libsemanage-python x86_64 2.1.10-18.el7 base 94 k
policycoreutils-python x86_64 2.2.5-20.el7 base 435 k
python-IPy noarch 0.75-6.el7 base 32 k
setools-libs x86_64 3.3.7-46.el7 base 485 k
Transaction Summary
==================================================================================================
Install 1 Package (+8 Dependent packages)
5.啟動docker deamon並將其設定成開機自啟動
[root@docker-machine ~]# systemctl start docker
[root@docker-machine ~]# systemctl enable docker
6.使用docker info命令驗證docker安裝是否正常
[root@docker-machine ~]# docker info
Containers: 0
Images: 0
Server Version: 1.9.1
Storage Driver: devicemapper
.....
.....
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.107-RHEL7 (2015-10-14)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
CPUs: 2
Total Memory: 1.947 GiB
Name: docker-machine
ID: TX5Y:GFE3:UDOT:2GCL:45MW:D75D:CS37:JWO2:GKNE:7WGX:IG63:JCK2
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
注:這裡遇到兩個警告,嘗試停止預設的firewalld服務,用iptables服務替換,警告依舊。目前還沒找到原因,但是不影響後面的使用
7.演示一些docker的基礎命令
7.1 檢視docker client和docker server的版本
[root@docker-machine ~]# docker version
Client:
Version: 1.9.1
API version: 1.21
Go version: go1.4.2
Git commit: a34a1d5
Built: Fri Nov 20 13:25:01 UTC 2015
OS/Arch: linux/amd64
Server:
Version: 1.9.1
API version: 1.21
Go version: go1.4.2
Git commit: a34a1d5
Built: Fri Nov 20 13:25:01 UTC 2015
OS/Arch: linux/amd64
7.2 安裝完docker後會多出一個內網ip段(給docker container使用)
[root@docker-machine ~]# ip addr
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 02:42:e6:44:58:df brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
7.3 查詢docker image
[root@docker-machine ~]# docker search jdk
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ingensi/oracle-jdk Official Oracle JDK installed on centos. 17 [OK]
jboss/base-jdk 14 [OK]
....
7.4 下載docker image——以hello-world映象為例
[root@docker-machine metadata]# docker pull hello-world
7.5 檢視下載的image list
[root@docker-machine metadata]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
hello-world latest 0a6ba66e537a 9 weeks ago 960 B --剛下載的image
7.6 檢視docker container list
簡單介紹幾個與該命令相關的引數:
-a:顯示所有的container,不加此引數預設只顯示正在執行的container
-l:顯示最近建立的container
[root@docker-machine metadata]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@docker-machine metadata]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
311f8051c47a hello-world "/hello" 6 seconds ago Created gloomy_williams
7628a02d613e hello-world "/hello" 53 seconds ago Created adoring_stallman
7.7 演示執行一個docker nginx image的過程
--下載docker nginx image
[root@docker-machine metadata]# docker pull nginx
[root@docker-machine metadata]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
nginx latest 5328fdfe9b8e 3 days ago 133.8 MB
--建立對應的靜態頁面目錄以及靜態頁面
[root@docker-machine metadata]# mkdir -p /var/www/html
[root@docker-machine metadata]# echo "good good study,day day up" > /var/www/html/index.html
--在新的coantainer中執行nginx
簡單介紹幾個與該命令相關的引數:
--name:給容器指定一個名字
-d:使容器在後臺執行
-v:繫結掛載點,將宿主機目錄掛載到container中的目錄上
-p:埠對映,將宿主主機埠對映到container中的埠
[root@docker-machine metadata]# docker run --name test-nginx2 -d -p 8080:80 -v /var/www/html:/usr/share/nginx/html:ro nginx
--測試docker nginx image
[root@docker-machine metadata]# curl
good good study,day day up
哈哈,成功了,第一次接觸docker,感覺很新穎。
1.檢視核心和作業系統版本
[root@docker-machine ~]# uname -r
3.10.0-327.el7.x86_64
[root@docker-machine ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
2.yum方式安裝——docker安裝提供了兩種方式,一種是yum,一種是透過scripts安裝,這裡我們選擇前者
[root@docker-machine ~]# yum update
3.新增yum repo
[root@docker-machine ~]# tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=
enabled=1
gpgcheck=1
gpgkey=
EOF
4.安裝docker
[root@docker-machine ~]# yum install docker-engine
=================================================================================================
Package Arch Version Repository Size
=================================================================================================
Installing:
docker-engine x86_64 1.9.1-1.el7.centos dockerrepo 8.2 M
Installing for dependencies:
audit-libs-python x86_64 2.4.1-5.el7 base 69 k
checkpolicy x86_64 2.1.12-6.el7 base 247 k
docker-engine-selinux noarch 1.9.1-1.el7.centos dockerrepo 21 k
libcgroup x86_64 0.41-8.el7 base 64 k
libsemanage-python x86_64 2.1.10-18.el7 base 94 k
policycoreutils-python x86_64 2.2.5-20.el7 base 435 k
python-IPy noarch 0.75-6.el7 base 32 k
setools-libs x86_64 3.3.7-46.el7 base 485 k
Transaction Summary
==================================================================================================
Install 1 Package (+8 Dependent packages)
5.啟動docker deamon並將其設定成開機自啟動
[root@docker-machine ~]# systemctl start docker
[root@docker-machine ~]# systemctl enable docker
6.使用docker info命令驗證docker安裝是否正常
[root@docker-machine ~]# docker info
Containers: 0
Images: 0
Server Version: 1.9.1
Storage Driver: devicemapper
.....
.....
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.107-RHEL7 (2015-10-14)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
CPUs: 2
Total Memory: 1.947 GiB
Name: docker-machine
ID: TX5Y:GFE3:UDOT:2GCL:45MW:D75D:CS37:JWO2:GKNE:7WGX:IG63:JCK2
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
注:這裡遇到兩個警告,嘗試停止預設的firewalld服務,用iptables服務替換,警告依舊。目前還沒找到原因,但是不影響後面的使用
7.演示一些docker的基礎命令
7.1 檢視docker client和docker server的版本
[root@docker-machine ~]# docker version
Client:
Version: 1.9.1
API version: 1.21
Go version: go1.4.2
Git commit: a34a1d5
Built: Fri Nov 20 13:25:01 UTC 2015
OS/Arch: linux/amd64
Server:
Version: 1.9.1
API version: 1.21
Go version: go1.4.2
Git commit: a34a1d5
Built: Fri Nov 20 13:25:01 UTC 2015
OS/Arch: linux/amd64
7.2 安裝完docker後會多出一個內網ip段(給docker container使用)
[root@docker-machine ~]# ip addr
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 02:42:e6:44:58:df brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 scope global docker0
valid_lft forever preferred_lft forever
7.3 查詢docker image
[root@docker-machine ~]# docker search jdk
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ingensi/oracle-jdk Official Oracle JDK installed on centos. 17 [OK]
jboss/base-jdk 14 [OK]
....
7.4 下載docker image——以hello-world映象為例
[root@docker-machine metadata]# docker pull hello-world
7.5 檢視下載的image list
[root@docker-machine metadata]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
hello-world latest 0a6ba66e537a 9 weeks ago 960 B --剛下載的image
7.6 檢視docker container list
簡單介紹幾個與該命令相關的引數:
-a:顯示所有的container,不加此引數預設只顯示正在執行的container
-l:顯示最近建立的container
[root@docker-machine metadata]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@docker-machine metadata]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
311f8051c47a hello-world "/hello" 6 seconds ago Created gloomy_williams
7628a02d613e hello-world "/hello" 53 seconds ago Created adoring_stallman
7.7 演示執行一個docker nginx image的過程
--下載docker nginx image
[root@docker-machine metadata]# docker pull nginx
[root@docker-machine metadata]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
nginx latest 5328fdfe9b8e 3 days ago 133.8 MB
--建立對應的靜態頁面目錄以及靜態頁面
[root@docker-machine metadata]# mkdir -p /var/www/html
[root@docker-machine metadata]# echo "good good study,day day up" > /var/www/html/index.html
--在新的coantainer中執行nginx
簡單介紹幾個與該命令相關的引數:
--name:給容器指定一個名字
-d:使容器在後臺執行
-v:繫結掛載點,將宿主機目錄掛載到container中的目錄上
-p:埠對映,將宿主主機埠對映到container中的埠
[root@docker-machine metadata]# docker run --name test-nginx2 -d -p 8080:80 -v /var/www/html:/usr/share/nginx/html:ro nginx
--測試docker nginx image
[root@docker-machine metadata]# curl
good good study,day day up
哈哈,成功了,第一次接觸docker,感覺很新穎。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/20801486/viewspace-1875261/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Docker安裝及基本命令Docker
- 小丸子學Docker系列之——實戰DockerfileDocker
- Docker 入門及安裝[Docker 系列-1]Docker
- 小丸子學Redis系列之——安裝RedisRedis
- 小丸子學MongoDB系列之——安裝MongoDBMongoDB
- Docker安裝及使用Docker
- docker安裝mongoDB及使用DockerMongoDB
- 【Docker 系列】docker 學習 二,Docker 的常用命令Docker
- [Docker 系列]docker 學習 二,Docker 的常用命令Docker
- 小丸子學Kubernetes系列之——Kubernetes安裝與使用
- 伺服器安裝docker 以及使用docker安裝mysql及svn伺服器DockerMySql
- Docker的安裝配置及使用詳解Docker
- docker安裝及解除安裝Docker
- 【Mac】Docker安裝及基礎使用MacDocker
- Docker基本介紹及使用Docker
- Docker入門教程:15個Docker基本命令及用法Docker
- Docker 容器基本操作[Docker 系列-2]Docker
- docker安裝使用Docker
- docker 學習之一:docker 安裝Docker
- docker學習1:CentOS Docker 安裝DockerCentOS
- docker學習6:Docker 安裝 NginxDockerNginx
- docker學習7:Docker 安裝 PHPDockerPHP
- Docker 快速入門系列-Docker 在 MacOS 安裝DockerMac
- docker基本命令Docker
- docker 基本命令Docker
- 使用Docker安裝Redis - 學習三DockerRedis
- docker 1.2 之docker基本用法Docker
- Docker 學習筆記-基本概念與安裝Docker筆記
- 在Ubuntu中安裝Docker和docker的使用UbuntuDocker
- Docker的基本使用及DockerFile的編寫Docker
- Docker簡介及安裝Docker
- Docker 快速入門系列-Docker 的基本組成Docker
- 『現學現忘』Docker基礎 — 22、使用Docker安裝NginxDockerNginx
- docker 學習筆記之實戰 lnmp 環境搭建系列 (1) —— docker 介紹與安裝Docker筆記LNMP
- Docker 入門系列一:docker 命令Docker
- Docker學習(二)- Docker 安裝 JenkinsDockerJenkins
- Docker部署系列之Docker Compose安裝Redis三主三從叢集DockerRedis
- 使用docker安裝nginxDockerNginx