docker ps check process
[root@VM_0_7_centos ~]# docker ps | awk '{print $2, $NF}'
ID NAMES
sameersbn/redmine:3.2.0-4 redmine
sameersbn/postgresql:9.4-12 postgresql-redmine
sameersbn/gitlab:8.4.4 gitlab
sameersbn/redis:latest gitlab-redis
sameersbn/postgresql:9.4-12 gitlab-postgre-sql
wordpress MyWordPress
mariadb db
Docker 有三个重要的概念:仓库(Repository)、镜像(Image)和容器(container)。
1.查询Docker的版本号
[root@VM_0_7_centos ~]# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version: docker-1.13.1-68.gitdded712.el7.centos.x86_64
Go version: go1.9.4
Git commit: dded712/1.13.1
Built: Tue Jul 17 18:34:48 2018
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Package version: docker-1.13.1-68.gitdded712.el7.centos.x86_64
Go version: go1.9.4
Git commit: dded712/1.13.1
Built: Tue Jul 17 18:34:48 2018
OS/Arch: linux/amd64
Experimental: false
2.查询镜像并下载
[root@VM_0_7_centos ~]# docker search tutorial
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/learn/tutorial 40
docker.io docker.io/georgeyord/reactjs-tutorial This is the backend of the React comment b... 5 [OK]
[root@VM_0_7_centos ~]# docker pull learn/tutorial
Using default tag: latest
Trying to pull repository docker.io/learn/tutorial ...
latest: Pulling from docker.io/learn/tutorial
271134aeb542: Pull complete
Digest: sha256:2933b82e7c2a72ad8ea89d58af5d1472e35dacd5b7233577483f58ff8f9338bd
Status: Downloaded newer image for docker.io/learn/tutorial:latest
3.创建并启动容器
[root@VM_0_7_centos ~]# docker run learn/tutorial echo "hello world"
hello world
4.修改容器:在基于“learn/tutorial”镜像的容器中安装ping软件包
[root@VM_0_7_centos ~]# docker run learn/tutorial apt-get install -y ping
Reading package lists...
Building dependency tree...
The following NEW packages will be installed:
iputils-ping
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 56.1 kB of archives.
After this operation, 143 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ precise/main iputils-ping amd64 3:20101006-1ubuntu1 [56.1 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 56.1 kB in 1s (35.7 kB/s)
Selecting previously unselected package iputils-ping.
(Reading database ... 7545 files and directories currently installed.)
Unpacking iputils-ping (from .../iputils-ping_3%3a20101006-1ubuntu1_amd64.deb) ...
Setting up iputils-ping (3:20101006-1ubuntu1) ...
5.创建新镜像
[root@VM_0_7_centos ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
eea2031913c4 learn/tutorial "apt-get install -..." About a minute ago Exited (0) 58 seconds ago tender_albattani
[root@VM_0_7_centos ~]# docker commit eea2031913c4 learn/ping
sha256:4a1ec3f1ac89c42c34b71e98a947593c2d46d81bb14cfb443d933cff30324d47
6.使用新镜像
[root@VM_0_7_centos ~]# docker run learn/ping ping www.baidu.com
PING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.
64 bytes from 115.239.210.27: icmp_req=1 ttl=250 time=12.8 ms
64 bytes from 115.239.210.27: icmp_req=2 ttl=250 time=12.4 ms
64 bytes from 115.239.210.27: icmp_req=3 ttl=250 time=12.3 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 12.371/12.558/12.830/0.196 ms
7.查询容器信息
[root@VM_0_7_centos ~]# docker ps
8.Docker进入容器方法
[root@VM_0_7_centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
learn/ping latest 4a1ec3f1ac89 7 minutes ago 140 MB
docker.io/wordpress latest 9414c91da9a8 11 days ago 408 MB
docker.io/sameersbn/gitlab latest 50237d0663bd 13 days ago 2.09 GB
docker.io/gitlab/gitlab-ce latest d87e1ba8aa5f 2 weeks ago 1.46 GB
docker.io/sameersbn/redis latest ad607f019b8c 2 weeks ago 84.8 MB
docker.io/mariadb latest 2c73b3262fff 2 weeks ago 363 MB
docker.io/hello-world latest 2cb0d9787c4d 5 weeks ago 1.85 kB
docker.io/sameersbn/gitlab 8.4.4 9d1069e2b30c 2 years ago 720 MB
docker.io/sameersbn/redmine 3.2.0-4 7eb43870e9c7 2 years ago 636 MB
docker.io/sameersbn/postgresql 9.4-12 a100f2a18ec3 2 years ago 231 MB
docker.io/learn/tutorial latest a7876479f1aa 5 years ago 128 MB
[root@VM_0_7_centos ~]# docker run -it learn/ping /bin/bash
root@58a0b59f7dc8:/# ping www.baidu.com
PING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.
64 bytes from 115.239.210.27: icmp_req=1 ttl=250 time=12.7 ms
^C
--- www.a.shifen.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 12.762/12.762/12.762/0.000 ms
root@58a0b59f7dc8:/# exit
exit
8.把新镜像上传仓库
- docker 上传的镜像要和hub里创建的一致,修改镜像名并上传
[root@VM_0_7_centos ~]# docker images learn/ping
REPOSITORY TAG IMAGE ID CREATED SIZE
learn/ping latest 4a1ec3f1ac89 25 minutes ago 140 MB
[root@VM_0_7_centos ~]# docker tag 4a1ec3f1ac89 jason1203/ping
[root@VM_0_7_centos ~]# docker push jason1203/ping
The push refers to a repository [docker.io/jason1203/ping]
be1a4de9bb94: Pushed
ee1ba0cc9b81: Mounted from learn/ping
latest: digest: sha256:4364f8d15855e73149ee3ae932331f5b466d3ac3b4f13b68d7c3ca7dfcb33e29 size: 740