docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4f9b77aafa46 centos "/bin/sh -c 'while t…" 6 seconds ago Up 5 seconds tender_hofstadter
docker top 4f9b77aafa46 UID PID PPID C STIME TTY TIME CMD root 14087 14066 0 17:42 ? 00:00:00 /bin/sh -c while true;do echo batype;sleep 1000;done root 14107 14087 0 17:42 ? 00:00:00 /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 1000
docker cp 容器id:容器内路径 目的主机的路径 [root@iZ2vc7kou0oyoo6bt2y0lcZ ~]# cd /home/ [root@iZ2vc7kou0oyoo6bt2y0lcZ home]# ls html [root@iZ2vc7kou0oyoo6bt2y0lcZ home]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4f9b77aafa46 centos "/bin/sh -c 'while t…" 4 hours ago Up 4 hours tender_hofstadter [root@iZ2vc7kou0oyoo6bt2y0lcZ home]# docker exec -it 4f9b77aafa46 /bin/bash [root@4f9b77aafa46 /]# ls bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var [root@4f9b77aafa46 /]# cd /home/ [root@4f9b77aafa46 home]# ls [root@4f9b77aafa46 home]# touch test.java [root@4f9b77aafa46 home]# ls test.java [root@4f9b77aafa46 home]# exit exit [root@iZ2vc7kou0oyoo6bt2y0lcZ home]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4f9b77aafa46 centos "/bin/sh -c 'while t…" 4 hours ago Up 4 hours tender_hofstadter [root@iZ2vc7kou0oyoo6bt2y0lcZ home]# docker cp 4f9b77aafa46:/home/test.java /home Successfully copied 1.54kB to /home [root@iZ2vc7kou0oyoo6bt2y0lcZ home]# ls html test.java # 拷贝是一个手动过程,未来我们使用 -v 卷的技术,可以实现,自动同步(容器内的/home路径和主机上的/home路径打通)
练习安装 Nginx
搜索镜像:docker search nginx (建议去 dockerHub 上去搜索)
下载镜像:docker pull nginx
启动镜像
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[root@iZ2vc7kou0oyoo6bt2y0lcZ home]# docker pull nginx Using default tag: latest latest: Pulling from library/nginx Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31 Status: Downloaded newer image for nginx:latest docker.io/library/nginx:latest # -d 后台运行 # --name="nginx01" 给容器命名 # -p 宿主机端口:容器内部端口 [root@iZ2vc7kou0oyoo6bt2y0lcZ home]# docker run -d --name nginx01 -p 515:80 nginx 614bbf44138a3e834008f5a33a71194c8e78d7f0e53bccbdfc4c9c9f0c0501cb [root@iZ2vc7kou0oyoo6bt2y0lcZ home]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 614bbf44138a nginx "/docker-entrypoint.…" 8 seconds ago Up 7 seconds 0.0.0.0:515->80/tcp, :::515->80/tcp nginx01 4f9b77aafa46 centos "/bin/sh -c 'while t…" 4 hours ago Up 4 hours tender_hofstadter
# 访问指向端口515 [root@iZ2vc7kou0oyoo6bt2y0lcZ home]# curl 0.0.0.0:515 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p>
<p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p> </body> </html>
可视化工具
1 2 3 4 5 6 7 8 9 10 11 12 13
[root@iZ2vc7kou0oyoo6bt2y0lcZ ~]# docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer Unable to find image 'portainer/portainer:latest' locally latest: Pulling from portainer/portainer
Digest: sha256:fb45b43738646048a0a0cc74fcee2865b69efde857e710126084ee5de9be0f3f Status: Downloaded newer image for portainer/portainer:latest a1b1156666edf6cad33eb299e35f543b823673a97a9756726d1fbc2cc571bc47 [root@iZ2vc7kou0oyoo6bt2y0lcZ ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a1b1156666ed portainer/portainer "/portainer" 8 seconds ago Up 7 seconds 0.0.0.0:8088->9000/tcp, :::8088->9000/tcp dreamy_goodall 614bbf44138a nginx "/docker-entrypoint.…" 8 minutes ago Up 8 minutes 0.0.0.0:515->80/tcp, :::515->80/tcp nginx01 4f9b77aafa46 centos "/bin/sh -c 'while t…" 4 hours ago Up 4 hours tender_hofstadter
测试访问
http://www.batype.com:8088/
连接本地 Local
进入之的连接页面
commit 镜像
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# 提交容器成为一个新的副本 docker commit # 命令和git原理类似 docker commit -m="提交的描述信息" -a="作者" 容器id 目标镜像名:[TAG] [root@iZ2vc7kou0oyoo6bt2y0lcZ ~]# docker commit -a="batype" -m="test" 614bbf44138a nginx001:18.16.0 sha256:7fcdd59c72c118bccfc2a6d94953e7d18d4a1afadeea0eee304117e917f0aabe [root@iZ2vc7kou0oyoo6bt2y0lcZ ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx001 18.16.0 7fcdd59c72c1 12 seconds ago 141MB nginx latest 605c77e624dd 22 months ago 141MB mysql latest 3218b38490ce 22 months ago 516MB centos latest 5d0da3dc9764 2 years ago 231MB portainer/portainer latest 580c0e4e98b0 2 years ago 79.1MB [root@iZ2vc7kou0oyoo6bt2y0lcZ ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a1b1156666ed portainer/portainer "/portainer" About an hour ago Up About an hour 0.0.0.0:8088->9000/tcp, :::8088->9000/tcp dreamy_goodall 614bbf44138a nginx "/docker-entrypoint.…" About an hour ago Up About an hour 0.0.0.0:515->80/tcp, :::515->80/tcp nginx01 4f9b77aafa46 centos "/bin/sh -c 'while t…" 5 hours ago Up 5 hours tender_hofstadter