首页 > 代码库 > Docker基础

Docker基础

Docker基础

一、检查物理机版本,实验环境rhel7.2

 

[root@foundation62 docker]# uname -r

3.10.0-327.el7.x86_64

[root@foundation62 docker]# cat /etc/os-release

NAME="Red Hat Enterprise Linux Server"

VERSION="7.2 (Maipo)"

ID="rhel"

ID_LIKE="fedora"

VERSION_ID="7.2"

PRETTY_NAME="Red Hat Enterprise Linux Server 7.2 (Maipo)"

ANSI_COLOR="0;31"

CPE_NAME="cpe:/o:redhat:enterprise_linux:7.2:GA:server"

HOME_URL="https://www.redhat.com/"

BUG_REPORT_URL="https://bugzilla.redhat.com/"

 

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"

REDHAT_BUGZILLA_PRODUCT_VERSION=7.2

REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"

REDHAT_SUPPORT_PRODUCT_VERSION="7.2"

 

二、安装Docker

 

[root@foundation62 docker]# ls

docker-engine-1.10.3-1.el7.centos.x86_64.rpm          nginx.tar

docker-engine-selinux-1.10.3-1.el7.centos.noarch.rpm  ubuntu.tar

[root@foundation62 docker]# rpm -ivh docker-engine-selinux-1.10.3-1.el7.centos.noarch.rpm

warning: docker-engine-selinux-1.10.3-1.el7.centos.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID 2c52609d: NOKEY

Preparing...                          ################################# [100%]

Updating / installing...

   1:docker-engine-selinux-1.10.3-1.el################################# [100%]

setsebool:  SELinux is disabled.

[root@foundation62 docker]# rpm -ivh docker-engine-1.10.3-1.el7.centos.x86_64.rpm

warning: docker-engine-1.10.3-1.el7.centos.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 2c52609d: NOKEY

Preparing...                          ################################# [100%]

Updating / installing...

   1:docker-engine-1.10.3-1.el7.centos################################# [100%]

[root@foundation62 docker]# ls

docker-engine-1.10.3-1.el7.centos.x86_64.rpm  docker-engine-selinux-1.10.3-1.el7.centos.noarch.rpm

[root@foundation62 docker]# docker version

Client:

 Version:      1.10.3

 API version:  1.22

 Go version:   go1.5.3

 Git commit:   20f81dd

 Built:        Thu Mar 10 15:39:25 2016

 OS/Arch:      linux/amd64

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

开启Docker

[root@foundation62 docker]# systemctl start docker

查看Docker状态

[root@foundation62 docker]# systemctl status docker

docker.service - Docker Application Container Engine

   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)

   Active: active (running) since Tue 2017-05-09 10:16:44 CST; 1s ago

     Docs: https://docs.docker.com

 Main PID: 6565 (docker)

   CGroup: /system.slice/docker.service

           └─6565 /usr/bin/docker daemon -H fd://

 

May 09 10:16:43 foundation62.ilt.example.com docker[6565]: time="2017-05-09T1...

May 09 10:16:43 foundation62.ilt.example.com docker[6565]: time="2017-05-09T1...

May 09 10:16:43 foundation62.ilt.example.com docker[6565]: time="2017-05-09T1...

May 09 10:16:44 foundation62.ilt.example.com docker[6565]: time="2017-05-09T1...

May 09 10:16:44 foundation62.ilt.example.com docker[6565]: time="2017-05-09T1...

May 09 10:16:44 foundation62.ilt.example.com docker[6565]: time="2017-05-09T1...

May 09 10:16:44 foundation62.ilt.example.com docker[6565]: time="2017-05-09T1...

May 09 10:16:44 foundation62.ilt.example.com docker[6565]: time="2017-05-09T1...

May 09 10:16:44 foundation62.ilt.example.com systemd[1]: Started Docker Appli...

May 09 10:16:44 foundation62.ilt.example.com docker[6565]: time="2017-05-09T1...

Hint: Some lines were ellipsized, use -l to show in full.

[root@foundation62 docker]# docker version

Client:

 Version:      1.10.3

 API version:  1.22

 Go version:   go1.5.3

 Git commit:   20f81dd

 Built:        Thu Mar 10 15:39:25 2016

 OS/Arch:      linux/amd64

 

Server:

 Version:      1.10.3

 API version:  1.22

 Go version:   go1.5.3

 Git commit:   20f81dd

 Built:        Thu Mar 10 15:39:25 2016

 OS/Arch:      linux/amd64

 

三、容器管理

 

查看容器状态

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

查看镜像状态

[root@foundation62 docker]# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

导入镜像

[root@foundation62 docker]# docker load -i ubuntu.tar

[root@foundation62 docker]# docker load -i nginx.tar

[root@foundation62 docker]# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

nginx               latest              af4b3d7d5401        14 months ago       190.5 MB

ubuntu              latest              07c86167cdc4        14 months ago       187.9 MB

创建容器

[root@foundation62 docker]# docker run -it ubuntu

root@60be275d99b8:/# ls

bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

root@60be275d99b8:/# [root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

60be275d99b8        ubuntu              "/bin/bash"         17 seconds ago      Up 15 seconds                           nostalgic_ritchie

创建容器,并给容器名称docker1ctrl+q+p将容器打入后台运行

[root@foundation62 docker]# docker run -it --name docker1 ubuntu

root@347ab6df8d56:/# ls

bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

root@347ab6df8d56:/# [root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

347ab6df8d56        ubuntu              "/bin/bash"         18 seconds ago      Up 15 seconds                           docker1

60be275d99b8        ubuntu              "/bin/bash"         2 minutes ago       Up 2 minutes                            nostalgic_ritchie

停止容器

[root@foundation62 docker]# docker stop nostalgic_ritchie

nostalgic_ritchie

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES

347ab6df8d56        ubuntu              "/bin/bash"         About a minute ago   Up About a minute                       docker1

查看所有的容器状态

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                      PORTS               NAMES

347ab6df8d56        ubuntu              "/bin/bash"         About a minute ago   Up About a minute                               docker1

60be275d99b8        ubuntu              "/bin/bash"         3 minutes ago        Exited (0) 13 seconds ago                       nostalgic_ritchie

删除容器docker1

[root@foundation62 docker]# docker rm docker1

Failed to remove container (docker1): Error response from daemon: Conflict, You cannot remove a running container. Stop the container before attempting removal or use -f

失败原因:运行中的容器无法删除

[root@foundation62 docker]# docker rm nostalgic_ritchie

nostalgic_ritchie

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

347ab6df8d56        ubuntu              "/bin/bash"         2 minutes ago       Up 2 minutes                            docker1

连接容器

[root@foundation62 docker]# docker attach docker1

root@347ab6df8d56:/# ls

bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

root@347ab6df8d56:/# ip addr show

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

       valid_lft forever preferred_lft forever

    inet6 ::1/128 scope host

       valid_lft forever preferred_lft forever

11: eth0@if12: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default

    link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff

    inet 172.17.0.3/16 scope global eth0

       valid_lft forever preferred_lft forever

    inet6 fe80::42:acff:fe11:3/64 scope link

       valid_lft forever preferred_lft forever

root@347ab6df8d56:/# exit

Exit

Exit退出容器时,容器停止运行

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES

347ab6df8d56        ubuntu              "/bin/bash"         3 minutes ago       Exited (0) 4 seconds ago                       docker1

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@foundation62 docker]# docker rm docker1

docker1

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@foundation62 docker]# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

nginx               latest              af4b3d7d5401        14 months ago       190.5 MB

ubuntu              latest              07c86167cdc4        14 months ago       187.9 MB

查看nginx镜像状态

[root@foundation62 docker]# docker images nginx

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

nginx               latest              af4b3d7d5401        14 months ago       190.5 MB

查看Ubuntu镜像状态

[root@foundation62 docker]# docker images ubuntu

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

ubuntu              latest              07c86167cdc4        14 months ago       187.9 MB

查看nginx镜像历史

[root@foundation62 docker]# docker history nginx

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

af4b3d7d5401        14 months ago       /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon o   0 B                 

1f13f00bff49        14 months ago       /bin/sh -c #(nop) EXPOSE 443/tcp 80/tcp         0 B                 

ca041140639d        14 months ago       /bin/sh -c ln -sf /dev/stdout /var/log/nginx/   0 B                 

991d91ef3b7a        14 months ago       /bin/sh -c apt-key adv --keyserver hkp://pgp.   65.38 MB            

0b9cb8ba0ed6        14 months ago       /bin/sh -c #(nop) ENV NGINX_VERSION=1.9.12-1~   0 B                 

e8ec4c78f0a1        14 months ago       /bin/sh -c #(nop) MAINTAINER NGINX Docker Mai   0 B                 

f50f9524513f        14 months ago       /bin/sh -c #(nop) CMD ["/bin/bash"]             0 B                 

61e59900d3c0        14 months ago       /bin/sh -c #(nop) ADD file:b5391cb13172fb513d   125.1 MB            

查看Ubuntu镜像历史

[root@foundation62 docker]# docker history ubuntu

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

07c86167cdc4        14 months ago       /bin/sh -c #(nop) CMD ["/bin/bash"]             0 B                 

220d2912ab1d        14 months ago       /bin/sh -c sed -i ‘s/^#\s*\(deb.*universe\)$/   1.895 kB            

cc77a2e3d72c        14 months ago       /bin/sh -c echo ‘#!/bin/sh‘ > /usr/sbin/polic   194.5 kB            

c8fa7cdceff3        14 months ago       /bin/sh -c #(nop) ADD file:b9504126dc55908988   187.7 MB           

创建容器,打入后台运行 

[root@foundation62 docker]# docker run -d nginx

f5eb5043361253231a5df1d1528f11021a4876d8a5cc9240f848a57d719b9e2c

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES

f5eb50433612        nginx               "nginx -g ‘daemon off"   8 seconds ago       Up 5 seconds        80/tcp, 443/tcp     pedantic_curie

创建5个容器,并打入后台运行

[root@foundation62 docker]# for i in {1..5};do docker run -d nginx;done

fcd49a3a6972c75d62cc1981b3b328270b6136917b27e3234533b847888a5d78

b21ca4b2a1dbbd2af9cee4026a06da8c75d10071519004f5e17c953f42b270bd

2c79273479d47b6a1d95f48767deef470033ff88639c5269db79bf4aeece7c4a

1bf2e223679d907f8394086a69562b3ef1795ab83923c267bd6c18af82025e4b

27fa29d25bbc51615b17a34ae866b819adf30fa21299cd373d55bd78b6d70a7b

查看正在运行的容器

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS               NAMES

27fa29d25bbc        nginx               "nginx -g ‘daemon off"   14 seconds ago       Up 12 seconds       80/tcp, 443/tcp     loving_colden

1bf2e223679d        nginx               "nginx -g ‘daemon off"   16 seconds ago       Up 13 seconds       80/tcp, 443/tcp     cocky_poitras

2c79273479d4        nginx               "nginx -g ‘daemon off"   18 seconds ago       Up 15 seconds       80/tcp, 443/tcp     focused_bose

b21ca4b2a1db        nginx               "nginx -g ‘daemon off"   20 seconds ago       Up 18 seconds       80/tcp, 443/tcp     suspicious_euclid

fcd49a3a6972        nginx               "nginx -g ‘daemon off"   22 seconds ago       Up 19 seconds       80/tcp, 443/tcp     nostalgic_einstein

f5eb50433612        nginx               "nginx -g ‘daemon off"   About a minute ago   Up About a minute   80/tcp, 443/tcp     pedantic_curie

查看正在运行的容器,仅显示容器ip

[root@foundation62 docker]# docker ps -q

27fa29d25bbc

1bf2e223679d

2c79273479d4

b21ca4b2a1db

fcd49a3a6972

f5eb50433612

停止正在运行的所有容器

[root@foundation62 docker]# docker stop `docker ps -q`

27fa29d25bbc

1bf2e223679d

2c79273479d4

b21ca4b2a1db

fcd49a3a6972

f5eb50433612

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS                      PORTS               NAMES

27fa29d25bbc        nginx               "nginx -g ‘daemon off"   About a minute ago   Exited (0) 19 seconds ago                       loving_colden

1bf2e223679d        nginx               "nginx -g ‘daemon off"   About a minute ago   Exited (0) 18 seconds ago                       cocky_poitras

2c79273479d4        nginx               "nginx -g ‘daemon off"   About a minute ago   Exited (0) 18 seconds ago                       focused_bose

b21ca4b2a1db        nginx               "nginx -g ‘daemon off"   About a minute ago   Exited (0) 17 seconds ago                       suspicious_euclid

fcd49a3a6972        nginx               "nginx -g ‘daemon off"   About a minute ago   Exited (0) 16 seconds ago                       nostalgic_einstein

f5eb50433612        nginx               "nginx -g ‘daemon off"   2 minutes ago        Exited (0) 15 seconds ago                       pedantic_curie

删除所有容器

[root@foundation62 docker]# docker rm `docker ps -aq`

27fa29d25bbc

1bf2e223679d

2c79273479d4

b21ca4b2a1db

fcd49a3a6972

f5eb50433612

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@foundation62 docker]# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

nginx               latest              af4b3d7d5401        14 months ago       190.5 MB

ubuntu              latest              07c86167cdc4        14 months ago       187.9 MB

创建容器docker1

[root@foundation62 docker]# docker run -it --name docker1 ubuntu

root@bc97ea2347a2:/# mkdir /docker

root@bc97ea2347a2:/# cd docker/

root@bc97ea2347a2:/docker# touch file{1..5}

root@bc97ea2347a2:/docker# ls

file1  file2  file3  file4  file5

root@bc97ea2347a2:/docker# [root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES

bc97ea2347a2        ubuntu              "/bin/bash"         About a minute ago   Up 58 seconds                           docker1

将容器docker1的内容更新到镜像Ubuntuv1

[root@foundation62 docker]# docker commit docker1 ubuntu:v1

sha256:ec2f819155c7ad8cfbcc6fa6b8a0889da1a5ac505a275369c25c65abd4f3cf66

[root@foundation62 docker]# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

ubuntu              v1                  ec2f819155c7        8 seconds ago       187.9 MB

nginx               latest              af4b3d7d5401        14 months ago       190.5 MB

ubuntu              latest              07c86167cdc4        14 months ago       187.9 MB

[root@foundation62 docker]# docker history ubuntu

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

07c86167cdc4        14 months ago       /bin/sh -c #(nop) CMD ["/bin/bash"]             0 B                 

220d2912ab1d        14 months ago       /bin/sh -c sed -i ‘s/^#\s*\(deb.*universe\)$/   1.895 kB            

cc77a2e3d72c        14 months ago       /bin/sh -c echo ‘#!/bin/sh‘ > /usr/sbin/polic   194.5 kB            

c8fa7cdceff3        14 months ago       /bin/sh -c #(nop) ADD file:b9504126dc55908988   187.7 MB            

 

[root@foundation62 docker]# docker history ubuntu:v1

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

ec2f819155c7        24 seconds ago      /bin/bash                                       0 B                 

07c86167cdc4        14 months ago       /bin/sh -c #(nop) CMD ["/bin/bash"]             0 B                 

220d2912ab1d        14 months ago       /bin/sh -c sed -i ‘s/^#\s*\(deb.*universe\)$/   1.895 kB            

cc77a2e3d72c        14 months ago       /bin/sh -c echo ‘#!/bin/sh‘ > /usr/sbin/polic   194.5 kB            

c8fa7cdceff3        14 months ago       /bin/sh -c #(nop) ADD file:b9504126dc55908988   187.7 MB            

[root@foundation62 docker]# docker images ubuntu

REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE

ubuntu              v1                  ec2f819155c7        About a minute ago   187.9 MB

ubuntu              latest              07c86167cdc4        14 months ago        187.9 MB

通过镜像Ubuntu:v1创建的容器docker2有之前的数据

[root@foundation62 docker]# docker run -it --name docker2 ubuntu:v1

root@13c0cded1323:/# cd /docker/

root@13c0cded1323:/docker# ls

file1  file2  file3  file4  file5

root@13c0cded1323:/docker# exit

exit

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

bc97ea2347a2        ubuntu              "/bin/bash"         5 minutes ago       Up 5 minutes                            docker1

[root@foundation62 docker]# docker stop docker1

docker1

[root@foundation62 docker]# docker rm docker1

docker1

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                          PORTS               NAMES

13c0cded1323        ubuntu:v1           "/bin/bash"         About a minute ago   Exited (0) About a minute ago                       docker2

[root@foundation62 docker]# docker history ubuntu:v1

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

ec2f819155c7        4 minutes ago       /bin/bash                                       0 B                 

07c86167cdc4        14 months ago       /bin/sh -c #(nop) CMD ["/bin/bash"]             0 B                 

220d2912ab1d        14 months ago       /bin/sh -c sed -i ‘s/^#\s*\(deb.*universe\)$/   1.895 kB            

cc77a2e3d72c        14 months ago       /bin/sh -c echo ‘#!/bin/sh‘ > /usr/sbin/polic   194.5 kB            

c8fa7cdceff3        14 months ago       /bin/sh -c #(nop) ADD file:b9504126dc55908988   187.7 MB            

[root@foundation62 docker]# ls

docker-engine-1.10.3-1.el7.centos.x86_64.rpm  docker-engine-selinux-1.10.3-1.el7.centos.noarch.rpm  nginx.tar  ubuntu.tar

[root@foundation62 docker]# docker cp nginx.tar docker2:/docker/

[root@foundation62 docker]# docker attach docker2

You cannot attach to a stopped container, start it first

[root@foundation62 docker]# docker start docker2

docker2

[root@foundation62 docker]# docker attach docker2

root@13c0cded1323:/#

root@13c0cded1323:/# cd /docker/

root@13c0cded1323:/docker# ls

file1  file2  file3  file4  file5  nginx.tar

root@13c0cded1323:/docker# rm -fr nginx.tar

root@13c0cded1323:/docker# [root@foundation62 docker]# docker logs docker2

root@13c0cded1323:/# cd /docker/

root@13c0cded1323:/docker# ls

file1  file2  file3  file4  file5

root@13c0cded1323:/docker# exit

exit

root@13c0cded1323:/#

root@13c0cded1323:/# cd /docker/

root@13c0cded1323:/docker# ls

file1  file2  file3  file4  file5  nginx.tar

root@13c0cded1323:/docker# rm -fr nginx.tar

[root@foundation62 docker]# docker diff docker2

C /root

A /root/.bash_history

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

13c0cded1323        ubuntu:v1           "/bin/bash"         7 minutes ago       Up 3 minutes                            docker2

[root@foundation62 docker]# docker stop docker2

docker2

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@foundation62 docker]# docker export -o docker2.tar docker2

[root@foundation62 docker]# ll docker2.tar

-rw-r--r-- 1 root root 196858880 May  9 15:54 docker2.tar

[root@foundation62 docker]# docker save -o ubuntu2.tar ubuntu:v1

[root@foundation62 docker]# docker images ubuntu

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

ubuntu              v1                  ec2f819155c7        12 minutes ago      187.9 MB

ubuntu              latest              07c86167cdc4        14 months ago       187.9 MB

[root@foundation62 docker]# docker rmi ubuntu:v1

Failed to remove image (ubuntu:v1): Error response from daemon: conflict: unable to remove repository reference "ubuntu:v1" (must force) - container 13c0cded1323 is using its referenced image ec2f819155c7

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES

13c0cded1323        ubuntu:v1           "/bin/bash"         11 minutes ago      Exited (0) 3 minutes ago                       docker2

[root@foundation62 docker]# docker rm docker2

docker2

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@foundation62 docker]# docker rmi ubuntu:v1

Untagged: ubuntu:v1

Deleted: sha256:ec2f819155c7ad8cfbcc6fa6b8a0889da1a5ac505a275369c25c65abd4f3cf66

Deleted: sha256:1318ce88c13b4ac8e336202217886c8ec7d354790678efa27a3c240a867011d8

[root@foundation62 docker]# docker images ubuntu

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

ubuntu              latest              07c86167cdc4        14 months ago       187.9 MB

[root@foundation62 docker]# docker load -i ubuntu2.tar

[root@foundation62 docker]# docker images ubuntu

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

ubuntu              v1                  ec2f819155c7        14 minutes ago      187.9 MB

ubuntu              latest              07c86167cdc4        14 months ago       187.9 MB

[root@foundation62 docker]# docker run -it --name docker1 ubuntu:v1

root@264862a22064:/# cd /docker/

root@264862a22064:/docker# ls

file1  file2  file3  file4  file5

root@264862a22064:/docker# exit

exit

[root@foundation62 docker]# docker history ubuntu

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

07c86167cdc4        14 months ago       /bin/sh -c #(nop) CMD ["/bin/bash"]             0 B                 

220d2912ab1d        14 months ago       /bin/sh -c sed -i ‘s/^#\s*\(deb.*universe\)$/   1.895 kB            

cc77a2e3d72c        14 months ago       /bin/sh -c echo ‘#!/bin/sh‘ > /usr/sbin/polic   194.5 kB            

c8fa7cdceff3        14 months ago       /bin/sh -c #(nop) ADD file:b9504126dc55908988   187.7 MB            

[root@foundation62 docker]# docker history ubuntu:v1

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

ec2f819155c7        16 minutes ago      /bin/bash                                       0 B                 

<missing>           14 months ago       /bin/sh -c #(nop) CMD ["/bin/bash"]             0 B                 

<missing>           14 months ago       /bin/sh -c sed -i ‘s/^#\s*\(deb.*universe\)$/   1.895 kB            

<missing>           14 months ago       /bin/sh -c echo ‘#!/bin/sh‘ > /usr/sbin/polic   194.5 kB            

<missing>           14 months ago       /bin/sh -c #(nop) ADD file:b9504126dc55908988   187.7 MB            

[root@foundation62 docker]# docker info

Containers: 1

 Running: 0

 Paused: 0

 Stopped: 1

Images: 13

Server Version: 1.10.3

Storage Driver: devicemapper

 Pool Name: docker-8:9-26884788-pool

 Pool Blocksize: 65.54 kB

 Base Device Size: 10.74 GB

 Backing Filesystem: xfs

 Data file: /dev/loop2

 Metadata file: /dev/loop3

 Data Space Used: 510.3 MB

 Data Space Total: 107.4 GB

 Data Space Available: 106.9 GB

 Metadata Space Used: 1.18 MB

 Metadata Space Total: 2.147 GB

 Metadata Space Available: 2.146 GB

 Udev Sync Supported: true

 Deferred Removal Enabled: false

 Deferred Deletion Enabled: false

 Deferred Deleted Device Count: 0

 Data loop file: /var/lib/docker/devicemapper/devicemapper/data

 WARNING: Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.

 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

Plugins:

 Volume: local

 Network: null host bridge

Kernel Version: 3.10.0-327.el7.x86_64

Operating System: Red Hat Enterprise Linux Server 7.2 (Maipo)

OSType: linux

Architecture: x86_64

CPUs: 4

Total Memory: 3.606 GiB

Name: foundation62.ilt.example.com

ID: ZJLH:GO2L:YEUS:IXXS:ZSOC:OE3M:4GSZ:OGEA:RWOH:7MCC:VIB6:7UMB

WARNING: bridge-nf-call-iptables is disabled

WARNING: bridge-nf-call-ip6tables is disabled

[root@foundation62 docker]# docker start docker1

docker1

[root@foundation62 docker]# docker attach docker1

root@264862a22064:/#

root@264862a22064:/# ping 172.25.254.62

PING 172.25.254.62 (172.25.254.62) 56(84) bytes of data.

64 bytes from 172.25.254.62: icmp_seq=1 ttl=64 time=0.099 ms

64 bytes from 172.25.254.62: icmp_seq=2 ttl=64 time=0.080 ms

^C

--- 172.25.254.62 ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 999ms

rtt min/avg/max/mdev = 0.080/0.089/0.099/0.013 ms

root@264862a22064:/# exit

exit

[root@foundation62 docker]# ip addr show docker0

8: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN

    link/ether 02:42:4a:13:8e:3f brd ff:ff:ff:ff:ff:ff

    inet 172.17.0.1/16 scope global docker0

       valid_lft forever preferred_lft forever

    inet6 fe80::42:4aff:fe13:8e3f/64 scope link

       valid_lft forever preferred_lft forever

[root@foundation62 docker]# brctl show

bridge name bridge id STP enabled interfaces

br0 8000.000000000000 no

docker0 8000.02424a138e3f no

virbr0 8000.525400314d69 yes virbr0-nic

virbr1 8000.525400a75b84 yes virbr1-nic

[root@foundation62 docker]# netstat -antlp | grep :8000

[root@foundation62 docker]# iptables -t nat -nL

Chain PREROUTING (policy ACCEPT)

target     prot opt source               destination         

PREROUTING_direct  all  --  0.0.0.0/0            0.0.0.0/0           

PREROUTING_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0           

PREROUTING_ZONES  all  --  0.0.0.0/0            0.0.0.0/0           

DOCKER     all  --  0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type LOCAL

 

Chain INPUT (policy ACCEPT)

target     prot opt source               destination         

 

Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination         

OUTPUT_direct  all  --  0.0.0.0/0            0.0.0.0/0           

DOCKER     all  --  0.0.0.0/0           !127.0.0.0/8          ADDRTYPE match dst-type LOCAL

 

Chain POSTROUTING (policy ACCEPT)

target     prot opt source               destination         

MASQUERADE  all  --  172.17.0.0/16        0.0.0.0/0           

RETURN     all  --  192.168.122.0/24     224.0.0.0/24        

RETURN     all  --  192.168.122.0/24     255.255.255.255     

MASQUERADE  tcp  --  192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-65535

MASQUERADE  udp  --  192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-65535

MASQUERADE  all  --  192.168.122.0/24    !192.168.122.0/24    

POSTROUTING_direct  all  --  0.0.0.0/0            0.0.0.0/0           

POSTROUTING_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0           

POSTROUTING_ZONES  all  --  0.0.0.0/0            0.0.0.0/0           

 

Chain DOCKER (2 references)

target     prot opt source               destination         

RETURN     all  --  0.0.0.0/0            0.0.0.0/0           

 

Chain OUTPUT_direct (1 references)

target     prot opt source               destination         

 

Chain POSTROUTING_ZONES (1 references)

target     prot opt source               destination         

POST_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto]

POST_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto]

POST_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto]

 

Chain POSTROUTING_ZONES_SOURCE (1 references)

target     prot opt source               destination         

 

Chain POSTROUTING_direct (1 references)

target     prot opt source               destination         

 

Chain POST_public (3 references)

target     prot opt source               destination         

POST_public_log  all  --  0.0.0.0/0            0.0.0.0/0           

POST_public_deny  all  --  0.0.0.0/0            0.0.0.0/0           

POST_public_allow  all  --  0.0.0.0/0            0.0.0.0/0           

 

Chain POST_public_allow (1 references)

target     prot opt source               destination         

 

Chain POST_public_deny (1 references)

target     prot opt source               destination         

 

Chain POST_public_log (1 references)

target     prot opt source               destination         

 

Chain PREROUTING_ZONES (1 references)

target     prot opt source               destination         

PRE_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto]

PRE_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto]

PRE_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto]

 

Chain PREROUTING_ZONES_SOURCE (1 references)

target     prot opt source               destination         

 

Chain PREROUTING_direct (1 references)

target     prot opt source               destination         

 

Chain PRE_public (3 references)

target     prot opt source               destination         

PRE_public_log  all  --  0.0.0.0/0            0.0.0.0/0           

PRE_public_deny  all  --  0.0.0.0/0            0.0.0.0/0           

PRE_public_allow  all  --  0.0.0.0/0            0.0.0.0/0           

 

Chain PRE_public_allow (1 references)

target     prot opt source               destination         

 

Chain PRE_public_deny (1 references)

target     prot opt source               destination         

 

Chain PRE_public_log (1 references)

target     prot opt source               destination         

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES

264862a22064        ubuntu:v1           "/bin/bash"         14 minutes ago      Exited (0) 11 minutes ago                       docker1

[root@foundation62 docker]# docker start docker1

docker1

[root@foundation62 docker]# docker attach docker1

root@264862a22064:/#

root@264862a22064:/# cd /docker/

root@264862a22064:/docker# ls

file1  file2  file3  file4  file5

root@264862a22064:/docker# rm -fr file1

root@264862a22064:/docker# rm -fr file2

root@264862a22064:/docker# rm -fr file2

root@264862a22064:/docker# rm -fr file3

root@264862a22064:/docker# ls

file4  file5

root@264862a22064:/docker# [root@foundation62 docker]# docker diff docker1

C /docker

D /docker/file3

D /docker/file1

D /docker/file2

C /root

A /root/.bash_history

[root@foundation62 docker]# docker logs docker1

root@264862a22064:/# cd /docker/

root@264862a22064:/docker# ls

file1  file2  file3  file4  file5

root@264862a22064:/docker# exit

exit

root@264862a22064:/#

root@264862a22064:/# ping 172.25.254.62

PING 172.25.254.62 (172.25.254.62) 56(84) bytes of data.

64 bytes from 172.25.254.62: icmp_seq=1 ttl=64 time=0.099 ms

64 bytes from 172.25.254.62: icmp_seq=2 ttl=64 time=0.080 ms

^C

--- 172.25.254.62 ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 999ms

rtt min/avg/max/mdev = 0.080/0.089/0.099/0.013 ms

root@264862a22064:/# exit

exit

root@264862a22064:/#

root@264862a22064:/# cd /docker/

root@264862a22064:/docker# ls

file1  file2  file3  file4  file5

root@264862a22064:/docker# rm -fr file1

root@264862a22064:/docker# rm -fr file2

root@264862a22064:/docker# rm -fr file2

root@264862a22064:/docker# rm -fr file3

root@264862a22064:/docker# ls

file4  file5

[root@foundation62 docker]# brctl show

bridge name bridge id STP enabled interfaces

br0 8000.000000000000 no

docker0 8000.02424a138e3f no veth0c84755

virbr0 8000.525400314d69 yes virbr0-nic

virbr1 8000.525400a75b84 yes virbr1-nic

[root@foundation62 docker]# docker run -it --name docker2 ubuntu

root@0547bc01402e:/# [root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

0547bc01402e        ubuntu              "/bin/bash"         13 seconds ago      Up 10 seconds                           docker2

264862a22064        ubuntu:v1           "/bin/bash"         18 minutes ago      Up 3 minutes                            docker1

[root@foundation62 docker]# brctl show

bridge name bridge id STP enabled interfaces

br0 8000.000000000000 no

docker0 8000.02424a138e3f no veth0083704

veth0c84755

virbr0 8000.525400314d69 yes virbr0-nic

virbr1 8000.525400a75b84 yes virbr1-nic

[root@foundation62 docker]# vim /etc/systemd/system

system/      system.conf  

[root@foundation62 docker]# vim /etc/systemd/system/

basic.target.wants/                          getty.target.wants/

bluetooth.target.wants/                      graphical.target.wants/

dbus-org.bluez.service                       multi-user.target.wants/

dbus-org.fedoraproject.FirewallD1.service    remote-fs.target.wants/

dbus-org.freedesktop.Avahi.service           sockets.target.wants/

dbus-org.freedesktop.NetworkManager.service  spice-vdagentd.target.wants/

dbus-org.freedesktop.nm-dispatcher.service   sysinit.target.wants/

default.target                               system-update.target.wants/

default.target.wants/                        timers.target.wants/

display-manager.service                      

[root@foundation62 docker]# vim /usr/lib/systemd/system/docker.service

[root@foundation62 docker]# vim /lib/systemd/system/docker.service

[root@foundation62 docker]# cp /lib/systemd/system/docker.service /etc/systemd/system/docker.service

[root@foundation62 docker]# docker history ubuntu

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

07c86167cdc4        14 months ago       /bin/sh -c #(nop) CMD ["/bin/bash"]             0 B                 

220d2912ab1d        14 months ago       /bin/sh -c sed -i ‘s/^#\s*\(deb.*universe\)$/   1.895 kB            

cc77a2e3d72c        14 months ago       /bin/sh -c echo ‘#!/bin/sh‘ > /usr/sbin/polic   194.5 kB            

c8fa7cdceff3        14 months ago       /bin/sh -c #(nop) ADD file:b9504126dc55908988   187.7 MB            

[root@foundation62 docker]# systemctl daemon-reload ^C

[root@foundation62 docker]# systemctl restart docker.service ^C

[root@foundation62 docker]# docker network ls

NETWORK ID          NAME                DRIVER

27317aeb260b        none                null                

037fe16dedeb        host                host                

6eb762562a1c        bridge              bridge              

[root@foundation62 docker]# docker network --help

 

Usage: docker network [OPTIONS] COMMAND [OPTIONS]

 

Commands:

  inspect                  Display detailed network information

  ls                       List all networks

  rm                       Remove a network

  create                   Create a network

  connect                  Connect container to a network

  disconnect               Disconnect container from a network

 

Run ‘docker network COMMAND --help‘ for more information on a command.

 

  --help             Print usage

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

0547bc01402e        ubuntu              "/bin/bash"         10 minutes ago      Up 10 minutes                           docker2

264862a22064        ubuntu:v1           "/bin/bash"         28 minutes ago      Up 13 minutes                           docker1

[root@foundation62 docker]# docker kill 0547bc01402e

0547bc01402e

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

264862a22064        ubuntu:v1           "/bin/bash"         28 minutes ago      Up 13 minutes                           docker1

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                        PORTS               NAMES

0547bc01402e        ubuntu              "/bin/bash"         11 minutes ago      Exited (137) 22 seconds ago                       docker2

264862a22064        ubuntu:v1           "/bin/bash"         29 minutes ago      Up 14 minutes                                     docker1

[root@foundation62 docker]# docker rename docker1 docker3

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                            PORTS               NAMES

0547bc01402e        ubuntu              "/bin/bash"         12 minutes ago      Exited (137) About a minute ago                       docker2

264862a22064        ubuntu:v1           "/bin/bash"         30 minutes ago      Up 15 minutes                                         docker3

[root@foundation62 docker]# docker rename docker2 docker4

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                            PORTS               NAMES

0547bc01402e        ubuntu              "/bin/bash"         12 minutes ago      Exited (137) About a minute ago                       docker4

264862a22064        ubuntu:v1           "/bin/bash"         30 minutes ago      Up 15 minutes                                         docker3

[root@foundation62 docker]# docker top docker3

UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD

root                16119               8697                0                   16:14               pts/2               00:00:00            /bin/bash

[root@foundation62 docker]# docker top docker4

Error response from daemon: Container docker4 is not running

[root@foundation62 docker]# docker start docker4

docker4

[root@foundation62 docker]# docker top docker4

UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD

root                18209               8697                2                   16:31               pts/3               00:00:00            /bin/bash

[root@foundation62 docker]# docker inspect docker3

[

    {

        "Id": "264862a220640e1915ee2f8271625e47878a2f25cb982c497573ebda2c060a5c",

        "Created": "2017-05-09T07:59:15.350158812Z",

        "Path": "/bin/bash",

        "Args": [],

        "State": {

            "Status": "running",

            "Running": true,

            "Paused": false,

            "Restarting": false,

            "OOMKilled": false,

            "Dead": false,

            "Pid": 16119,

            "ExitCode": 0,

            "Error": "",

            "StartedAt": "2017-05-09T08:14:17.494384517Z",

            "FinishedAt": "2017-05-09T08:02:48.201541409Z"

        },

        "Image": "sha256:ec2f819155c7ad8cfbcc6fa6b8a0889da1a5ac505a275369c25c65abd4f3cf66",

        "ResolvConfPath": "/var/lib/docker/containers/264862a220640e1915ee2f8271625e47878a2f25cb982c497573ebda2c060a5c/resolv.conf",

        "HostnamePath": "/var/lib/docker/containers/264862a220640e1915ee2f8271625e47878a2f25cb982c497573ebda2c060a5c/hostname",

        "HostsPath": "/var/lib/docker/containers/264862a220640e1915ee2f8271625e47878a2f25cb982c497573ebda2c060a5c/hosts",

        "LogPath": "/var/lib/docker/containers/264862a220640e1915ee2f8271625e47878a2f25cb982c497573ebda2c060a5c/264862a220640e1915ee2f8271625e47878a2f25cb982c497573ebda2c060a5c-json.log",

        "Name": "/docker3",

        "RestartCount": 0,

        "Driver": "devicemapper",

        "MountLabel": "",

        "ProcessLabel": "",

        "AppArmorProfile": "",

        "ExecIDs": null,

        "HostConfig": {

            "Binds": null,

            "ContainerIDFile": "",

            "LogConfig": {

                "Type": "json-file",

                "Config": {}

            },

            "NetworkMode": "default",

            "PortBindings": {},

            "RestartPolicy": {

                "Name": "no",

                "MaximumRetryCount": 0

            },

            "VolumeDriver": "",

            "VolumesFrom": null,

            "CapAdd": null,

            "CapDrop": null,

            "Dns": [],

            "DnsOptions": [],

            "DnsSearch": [],

            "ExtraHosts": null,

            "GroupAdd": null,

            "IpcMode": "",

            "Links": null,

            "OomScoreAdj": 0,

            "PidMode": "",

            "Privileged": false,

            "PublishAllPorts": false,

            "ReadonlyRootfs": false,

            "SecurityOpt": null,

            "UTSMode": "",

            "ShmSize": 67108864,

            "ConsoleSize": [

                0,

                0

            ],

            "Isolation": "",

            "CpuShares": 0,

            "CgroupParent": "",

            "BlkioWeight": 0,

            "BlkioWeightDevice": null,

            "BlkioDeviceReadBps": null,

            "BlkioDeviceWriteBps": null,

            "BlkioDeviceReadIOps": null,

            "BlkioDeviceWriteIOps": null,

            "CpuPeriod": 0,

            "CpuQuota": 0,

            "CpusetCpus": "",

            "CpusetMems": "",

            "Devices": [],

            "KernelMemory": 0,

            "Memory": 0,

            "MemoryReservation": 0,

            "MemorySwap": 0,

            "MemorySwappiness": -1,

            "OomKillDisable": false,

            "PidsLimit": 0,

            "Ulimits": null

        },

        "GraphDriver": {

            "Name": "devicemapper",

            "Data": {

                "DeviceId": "85",

                "DeviceName": "docker-8:9-26884788-edb4944a181777997b2989cbbed31c50f414d3c8c35e56186a13962b4883a206",

                "DeviceSize": "10737418240"

            }

        },

        "Mounts": [],

        "Config": {

            "Hostname": "264862a22064",

            "Domainname": "",

            "User": "",

            "AttachStdin": true,

            "AttachStdout": true,

            "AttachStderr": true,

            "Tty": true,

            "OpenStdin": true,

            "StdinOnce": true,

            "Env": [],

            "Cmd": [

                "/bin/bash"

            ],

            "Image": "ubuntu:v1",

            "Volumes": null,

            "WorkingDir": "",

            "Entrypoint": null,

            "OnBuild": null,

            "Labels": {},

            "StopSignal": "SIGTERM"

        },

        "NetworkSettings": {

            "Bridge": "",

            "SandboxID": "cc4567f6dac3c3c318a98e5f22616d76f535889a38ceb92489b4728918036f06",

            "HairpinMode": false,

            "LinkLocalIPv6Address": "",

            "LinkLocalIPv6PrefixLen": 0,

            "Ports": {},

            "SandboxKey": "/var/run/docker/netns/cc4567f6dac3",

            "SecondaryIPAddresses": null,

            "SecondaryIPv6Addresses": null,

            "EndpointID": "2dbe467ed4f85222d5f88d0915741f746462525c960ea9e1f7978a655f493f5d",

            "Gateway": "172.17.0.1",

            "GlobalIPv6Address": "",

            "GlobalIPv6PrefixLen": 0,

            "IPAddress": "172.17.0.2",

            "IPPrefixLen": 16,

            "IPv6Gateway": "",

            "MacAddress": "02:42:ac:11:00:02",

            "Networks": {

                "bridge": {

                    "IPAMConfig": null,

                    "Links": null,

                    "Aliases": null,

                    "NetworkID": "6eb762562a1ce18c2cebf8b8bb89ba68e6044aeb2afa7248f5c6280115d8cf25",

                    "EndpointID": "2dbe467ed4f85222d5f88d0915741f746462525c960ea9e1f7978a655f493f5d",

                    "Gateway": "172.17.0.1",

                    "IPAddress": "172.17.0.2",

                    "IPPrefixLen": 16,

                    "IPv6Gateway": "",

                    "GlobalIPv6Address": "",

                    "GlobalIPv6PrefixLen": 0,

                    "MacAddress": "02:42:ac:11:00:02"

                }

            }

        }

    }

]

[root@foundation62 docker]# docker stop docker3

docker3

[root@foundation62 docker]# docker rm docker3

docker3

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

0547bc01402e        ubuntu              "/bin/bash"         18 minutes ago      Up 3 minutes                            docker4

[root@foundation62 docker]# docker stop docker4

docker4

[root@foundation62 docker]# docker rm docker4

docker4

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@foundation62 docker]# docker run -it --name docker1 -v /tmp/data1:/data1 ubuntu

root@d5b97a8493ce:/# cd /data1/

root@d5b97a8493ce:/data1# ls

root@d5b97a8493ce:/data1# touch file1

root@d5b97a8493ce:/data1# ls

file1

root@d5b97a8493ce:/data1# [root@foundation62 docker]# cd /tmp/data1/

[root@foundation62 data1]# ls

file1

[root@foundation62 data1]# touch file2

[root@foundation62 data1]# ls

file1  file2

[root@foundation62 data1]# docker attach docker1

 

root@d5b97a8493ce:/data1# ls

file1  file2

root@d5b97a8493ce:/data1# exit

exit

[root@foundation62 data1]# touch file3

[root@foundation62 data1]# ls

file1  file2  file3

[root@foundation62 data1]# docker start docker1

docker1

[root@foundation62 data1]# docker attach docker1

root@d5b97a8493ce:/#

root@d5b97a8493ce:/# ls

bin  boot  data1  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

root@d5b97a8493ce:/# cd /data1/

root@d5b97a8493ce:/data1# ls

file1  file2  file3

root@d5b97a8493ce:/data1# exit

exit

[root@foundation62 data1]# cp /etc/passwd .

[root@foundation62 data1]# ls

file1  file2  file3  passwd

[root@foundation62 data1]# cp /etc/fstab .

[root@foundation62 data1]# ls

file1  file2  file3  fstab  passwd

[root@foundation62 data1]# docker run -it --name docker2 -v /tmp/data1:/data1 -v /tmp/data2:/data2 ubuntu

root@c747291d1f50:/# cd /data2

root@c747291d1f50:/data2# cp /data1/passwd .

root@c747291d1f50:/data2# ls

passwd

root@c747291d1f50:/data2# exit

exit

[root@foundation62 data1]# cd /tmp/data2

[root@foundation62 data2]# ls

passwd

[root@foundation62 data2]# touch file3

[root@foundation62 data2]# ls

file3  passwd

[root@foundation62 data2]# docker run -it --name docker3 -v /tmp/data1:/data1 -v /tmp/data2:/data2:ro -v /tmp/data3:/data3:ro ubuntu

root@014a70b62d0c:/# cd /data2

root@014a70b62d0c:/data2# ls

file3  passwd

root@014a70b62d0c:/data2# rm -fr file3

rm: cannot remove ‘file3‘: Read-only file system

root@014a70b62d0c:/data2# cd /data3

root@014a70b62d0c:/data3# ls

root@014a70b62d0c:/data3# touch file

touch: cannot touch ‘file‘: Read-only file system

root@014a70b62d0c:/data3# exit

exit

[root@foundation62 data2]# cd /tmp/data1

[root@foundation62 data1]# ls

file1  file2  file3  fstab  passwd

[root@foundation62 data1]# rm -fr file2

[root@foundation62 data1]# cd /tmp/data2

[root@foundation62 data2]# ls

file3  passwd

[root@foundation62 data2]# touch file

[root@foundation62 data2]# ls

file  file3  passwd

[root@foundation62 data2]# cd /tmp/data3

[root@foundation62 data3]# ls

[root@foundation62 data3]# touch file

[root@foundation62 data3]# ls

file

[root@foundation62 data3]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@foundation62 data3]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                          PORTS               NAMES

014a70b62d0c        ubuntu              "/bin/bash"         About a minute ago   Exited (1) About a minute ago                       docker3

c747291d1f50        ubuntu              "/bin/bash"         19 minutes ago       Exited (0) 18 minutes ago                           docker2

d5b97a8493ce        ubuntu              "/bin/bash"         23 minutes ago       Exited (0) 21 minutes ago                           docker1

[root@foundation62 data3]# docker start docker1

docker1

[root@foundation62 data3]# docker start docker2

docker2

[root@foundation62 data3]# docker start docker3

docker3

[root@foundation62 data3]# do

do          docker      domainname  done        dosfsck     dosfslabel  

[root@foundation62 data3]# docker attach docker1

root@d5b97a8493ce:/#

root@d5b97a8493ce:/# cd /data1/

root@d5b97a8493ce:/data1# ls

file1  file3  fstab  passwd

root@d5b97a8493ce:/data1# [root@foundation62 data3]# docker attach docker2

root@c747291d1f50:/#

root@c747291d1f50:/# cd /data2

root@c747291d1f50:/data2# ls

file  file3  passwd

root@c747291d1f50:/data2# [root@foundation62 data3]# docker attach docker3

root@014a70b62d0c:/#

root@014a70b62d0c:/# cd /data2

root@014a70b62d0c:/data2# ls

file  file3  passwd

root@014a70b62d0c:/data2# rm -fr file

rm: cannot remove ‘file‘: Read-only file system

root@014a70b62d0c:/data2# cd /data3

root@014a70b62d0c:/data3# ls

file

root@014a70b62d0c:/data3# rm -fr file

rm: cannot remove ‘file‘: Read-only file system

root@014a70b62d0c:/data3# [root@foundation62 data3]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

014a70b62d0c        ubuntu              "/bin/bash"         5 minutes ago       Up 3 minutes                            docker3

c747291d1f50        ubuntu              "/bin/bash"         22 minutes ago      Up 3 minutes                            docker2

d5b97a8493ce        ubuntu              "/bin/bash"         26 minutes ago      Up 3 minutes                            docker1

[root@foundation62 data3]# docker create --name datavol -v /tmp/data1:/data1 -v /tmp/data2:/data2 -v /tmp/data3:/data3:ro -v /etc/yum.repos.d:/etc/yum.repo.d:ro ubuntu

fa04aa88619142106235d97e2bdaae22b5076549c1b32a719d68aa047631f663

[root@foundation62 data3]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

fa04aa886191        ubuntu              "/bin/bash"         43 seconds ago      Created                                 datavol

014a70b62d0c        ubuntu              "/bin/bash"         14 minutes ago      Up 12 minutes                           docker3

c747291d1f50        ubuntu              "/bin/bash"         31 minutes ago      Up 12 minutes                           docker2

d5b97a8493ce        ubuntu              "/bin/bash"         36 minutes ago      Up 12 minutes                           docker1

[root@foundation62 data3]# docker run -it --name docker4 --volumes-from datavol ubuntu

root@ee6e065d8af5:/# cd /data1

root@ee6e065d8af5:/data1# ls

file1  file3  fstab  passwd

root@ee6e065d8af5:/data1# cd /data2

root@ee6e065d8af5:/data2# ls

file  file3  passwd

root@ee6e065d8af5:/data2# cd /data3

root@ee6e065d8af5:/data3# ls

file

root@ee6e065d8af5:/data3# rm -fr file

rm: cannot remove ‘file‘: Read-only file system

root@ee6e065d8af5:/data3# cd /etc/yum.repo.d/

root@ee6e065d8af5:/etc/yum.repo.d# ls

redhat.repo  rhel.repo

root@ee6e065d8af5:/etc/yum.repo.d# echo 1 >rhel.repo

bash: rhel.repo: Read-only file system

root@ee6e065d8af5:/etc/yum.

[root@foundation62 data3]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES

ee6e065d8af5        ubuntu              "/bin/bash"         About a minute ago   Up About a minute                       docker4

fa04aa886191        ubuntu              "/bin/bash"         2 minutes ago        Created                                 datavol

014a70b62d0c        ubuntu              "/bin/bash"         17 minutes ago       Up 14 minutes                           docker3

c747291d1f50        ubuntu              "/bin/bash"         34 minutes ago       Up 14 minutes                           docker2

d5b97a8493ce        ubuntu              "/bin/bash"         38 minutes ago       Up 14 minutes                           docker1

[root@foundation62 data3]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES

ee6e065d8af5        ubuntu              "/bin/bash"         About a minute ago   Up About a minute                       docker4

014a70b62d0c        ubuntu              "/bin/bash"         17 minutes ago       Up 14 minutes                           docker3

c747291d1f50        ubuntu              "/bin/bash"         34 minutes ago       Up 14 minutes                           docker2

d5b97a8493ce        ubuntu              "/bin/bash"         38 minutes ago       Up 14 minutes                           docker1

[root@foundation62 data3]# docker run -rm ubuntu echo westos

flag provided but not defined: -rm

See ‘docker run --help‘.

[root@foundation62 data3]# docker run --rm ubuntu echo westos

westos

[root@foundation62 data3]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

ee6e065d8af5        ubuntu              "/bin/bash"         3 minutes ago       Up 3 minutes                            docker4

fa04aa886191        ubuntu              "/bin/bash"         5 minutes ago       Created                                 datavol

014a70b62d0c        ubuntu              "/bin/bash"         19 minutes ago      Up 17 minutes                           docker3

c747291d1f50        ubuntu              "/bin/bash"         36 minutes ago      Up 17 minutes                           docker2

d5b97a8493ce        ubuntu              "/bin/bash"         40 minutes ago      Up 17 minutes                           docker1

[root@foundation62 data3]# cd /docker/

[root@foundation62 docker]# ls

docker2.tar                                   docker-engine-selinux-1.10.3-1.el7.centos.noarch.rpm  ubuntu2.tar

docker-engine-1.10.3-1.el7.centos.x86_64.rpm  nginx.tar                                             ubuntu.tar

[root@foundation62 docker]# docker cp docker4:/data2/file .

[root@foundation62 docker]# ls

docker2.tar                                   docker-engine-selinux-1.10.3-1.el7.centos.noarch.rpm  nginx.tar    ubuntu.tar

docker-engine-1.10.3-1.el7.centos.x86_64.rpm  file                                                  ubuntu2.tar

[root@foundation62 docker]# ll file

-rw-r--r-- 1 root root 0 May  9 17:00 file

[root@foundation62 docker]# rm -fr file

[root@foundation62 docker]# docker run --rm -v /tmp/backup:/backup ubuntu tar cf /backup/etc.tar /etc

tar: Removing leading `/‘ from member names

[root@foundation62 docker]# cd /tmp/backup/

[root@foundation62 backup]# ls

etc.tar

[root@foundation62 backup]# tar tf etc.tar | less

[root@foundation62 backup]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

ee6e065d8af5        ubuntu              "/bin/bash"         8 minutes ago       Up 8 minutes                            docker4

fa04aa886191        ubuntu              "/bin/bash"         9 minutes ago       Created                                 datavol

014a70b62d0c        ubuntu              "/bin/bash"         23 minutes ago      Up 21 minutes                           docker3

c747291d1f50        ubuntu              "/bin/bash"         41 minutes ago      Up 21 minutes                           docker2

d5b97a8493ce        ubuntu              "/bin/bash"         45 minutes ago      Up 21 minutes                           docker1

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

ee6e065d8af5        ubuntu              "/bin/bash"         11 minutes ago      Up 11 minutes                           docker4

014a70b62d0c        ubuntu              "/bin/bash"         27 minutes ago      Up 25 minutes                           docker3

c747291d1f50        ubuntu              "/bin/bash"         44 minutes ago      Up 25 minutes                           docker2

d5b97a8493ce        ubuntu              "/bin/bash"         48 minutes ago      Up 25 minutes                           docker1

[root@foundation62 docker]# docker run -d --name docker5 -p 8000:800 nginx

786ba451b2ee8e74c62028997369eb0337a728a25270d12e0508940b4b91c019

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                    NAMES

786ba451b2ee        nginx               "nginx -g ‘daemon off"   13 seconds ago      Up 9 seconds        80/tcp, 443/tcp, 0.0.0.0:8000->800/tcp   docker5

ee6e065d8af5        ubuntu              "/bin/bash"              12 minutes ago      Up 12 minutes                                                docker4

014a70b62d0c        ubuntu              "/bin/bash"              28 minutes ago      Up 25 minutes                                                docker3

c747291d1f50        ubuntu              "/bin/bash"              45 minutes ago      Up 26 minutes                                                docker2

d5b97a8493ce        ubuntu              "/bin/bash"              49 minutes ago      Up 26 minutes                                                docker1

[root@foundation62 docker]# netstat -antlp | grep :8000

tcp6       0      0 :::8000                 :::*                    LISTEN      22997/docker-proxy  

[root@foundation62 docker]# iptables -t nat -nL

Chain PREROUTING (policy ACCEPT)

target     prot opt source               destination         

PREROUTING_direct  all  --  0.0.0.0/0            0.0.0.0/0           

PREROUTING_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0           

PREROUTING_ZONES  all  --  0.0.0.0/0            0.0.0.0/0           

DOCKER     all  --  0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type LOCAL

 

Chain INPUT (policy ACCEPT)

target     prot opt source               destination         

 

Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination         

OUTPUT_direct  all  --  0.0.0.0/0            0.0.0.0/0           

DOCKER     all  --  0.0.0.0/0           !127.0.0.0/8          ADDRTYPE match dst-type LOCAL

 

Chain POSTROUTING (policy ACCEPT)

target     prot opt source               destination         

MASQUERADE  all  --  172.17.0.0/16        0.0.0.0/0           

RETURN     all  --  192.168.122.0/24     224.0.0.0/24        

RETURN     all  --  192.168.122.0/24     255.255.255.255     

MASQUERADE  tcp  --  192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-65535

MASQUERADE  udp  --  192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-65535

MASQUERADE  all  --  192.168.122.0/24    !192.168.122.0/24    

POSTROUTING_direct  all  --  0.0.0.0/0            0.0.0.0/0           

POSTROUTING_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0           

POSTROUTING_ZONES  all  --  0.0.0.0/0            0.0.0.0/0           

MASQUERADE  tcp  --  172.17.0.6           172.17.0.6           tcp dpt:800

 

Chain DOCKER (2 references)

target     prot opt source               destination         

RETURN     all  --  0.0.0.0/0            0.0.0.0/0           

DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:8000 to:172.17.0.6:800

 

Chain OUTPUT_direct (1 references)

target     prot opt source               destination         

 

Chain POSTROUTING_ZONES (1 references)

target     prot opt source               destination         

POST_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto]

POST_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto]

POST_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto]

 

Chain POSTROUTING_ZONES_SOURCE (1 references)

target     prot opt source               destination         

 

Chain POSTROUTING_direct (1 references)

target     prot opt source               destination         

 

Chain POST_public (3 references)

target     prot opt source               destination         

POST_public_log  all  --  0.0.0.0/0            0.0.0.0/0           

POST_public_deny  all  --  0.0.0.0/0            0.0.0.0/0           

POST_public_allow  all  --  0.0.0.0/0            0.0.0.0/0           

 

Chain POST_public_allow (1 references)

target     prot opt source               destination         

 

Chain POST_public_deny (1 references)

target     prot opt source               destination         

 

Chain POST_public_log (1 references)

target     prot opt source               destination         

 

Chain PREROUTING_ZONES (1 references)

target     prot opt source               destination         

PRE_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto]

PRE_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto]

PRE_public  all  --  0.0.0.0/0            0.0.0.0/0           [goto]

 

Chain PREROUTING_ZONES_SOURCE (1 references)

target     prot opt source               destination         

 

Chain PREROUTING_direct (1 references)

target     prot opt source               destination         

 

Chain PRE_public (3 references)

target     prot opt source               destination         

PRE_public_log  all  --  0.0.0.0/0            0.0.0.0/0           

PRE_public_deny  all  --  0.0.0.0/0            0.0.0.0/0           

PRE_public_allow  all  --  0.0.0.0/0            0.0.0.0/0           

 

Chain PRE_public_allow (1 references)

target     prot opt source               destination         

 

Chain PRE_public_deny (1 references)

target     prot opt source               destination         

 

Chain PRE_public_log (1 references)

target     prot opt source               destination         

[root@foundation62 docker]# iptables -L

Chain INPUT (policy ACCEPT)

target     prot opt source               destination         

ACCEPT     udp  --  anywhere             anywhere             udp dpt:domain

ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:domain

ACCEPT     udp  --  anywhere             anywhere             udp dpt:bootps

ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:bootps

ACCEPT     udp  --  anywhere             anywhere             udp dpt:domain

ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:domain

ACCEPT     udp  --  anywhere             anywhere             udp dpt:bootps

ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:bootps

ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED

ACCEPT     all  --  anywhere             anywhere            

INPUT_direct  all  --  anywhere             anywhere            

INPUT_ZONES_SOURCE  all  --  anywhere             anywhere            

INPUT_ZONES  all  --  anywhere             anywhere            

ACCEPT     icmp --  anywhere             anywhere            

REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

 

Chain FORWARD (policy ACCEPT)

target     prot opt source               destination         

DOCKER-ISOLATION  all  --  anywhere             anywhere            

DOCKER     all  --  anywhere             anywhere            

ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED

ACCEPT     all  --  anywhere             anywhere            

ACCEPT     all  --  anywhere             anywhere            

ACCEPT     all  --  anywhere             anywhere            

REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable

REJECT     all  --  anywhere             anywhere             reject-with icmp-port-unreachable

^C

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                    NAMES

786ba451b2ee        nginx               "nginx -g ‘daemon off"   3 minutes ago       Up 3 minutes        80/tcp, 443/tcp, 0.0.0.0:8000->800/tcp   docker5

ee6e065d8af5        ubuntu              "/bin/bash"              15 minutes ago      Up 15 minutes                                                docker4

014a70b62d0c        ubuntu              "/bin/bash"              31 minutes ago      Up 28 minutes                                                docker3

c747291d1f50        ubuntu              "/bin/bash"              48 minutes ago      Up 28 minutes                                                docker2

d5b97a8493ce        ubuntu              "/bin/bash"              52 minutes ago      Up 29 minutes                                                docker1

[root@foundation62 docker]# docker stop docker{1..5}

docker1

docker2

docker3

docker4

docker5

[root@foundation62 docker]# docker ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES

786ba451b2ee        nginx               "nginx -g ‘daemon off"   5 minutes ago       Exited (0) 10 seconds ago                       docker5

ee6e065d8af5        ubuntu              "/bin/bash"              17 minutes ago      Exited (1) 11 seconds ago                       docker4

fa04aa886191        ubuntu              "/bin/bash"              19 minutes ago      Created                                         datavol

014a70b62d0c        ubuntu              "/bin/bash"              33 minutes ago      Exited (1) 12 seconds ago                       docker3

c747291d1f50        ubuntu              "/bin/bash"              50 minutes ago      Exited (0) 13 seconds ago                       docker2

d5b97a8493ce        ubuntu              "/bin/bash"              54 minutes ago      Exited (0) 14 seconds ago                       docker1

[root@foundation62 docker]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@foundation62 docker]# 

Docker基础