[root@yz6205 ~]# docker images
INFO[0063] GET /v1.19/images/json REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu latest 7bd023c8937d 41 hours ago 122 MBubuntu 14.04 0e7d4a488bcc 41 hours ago 187.9 MBcentos latest db0f5936b391 11 days ago 196.7 MB[root@yz6205 ~]# docker run -t -i ubuntu /bin/bash INFO[0127] POST /v1.19/containers/create INFO[0143] POST /v1.19/containers/5b1280645766492db1bf43f54a17b934038a2bfa3b9a45ba161bd0653e406a78/attach?stderr=1&stdin=1&stdout=1&stream=1 INFO[0143] POST /v1.19/containers/5b1280645766492db1bf43f54a17b934038a2bfa3b9a45ba161bd0653e406a78/start INFO[0143] POST /v1.19/containers/5b1280645766492db1bf43f54a17b934038a2bfa3b9a45ba161bd0653e406a78/resize?h=26&w=121 root@5b1280645766:/#创建镜像
1,基于已有镜像的容器创建root@68dea79aa079:~# cat /etc/issueUbuntu 16.04 LTS \n \l[root@yz6205 ~]# docker commit -m "Add a new file" -a "docker newbee" 68dea79aa079 test
933b24d02ecfacb81ad0afa1c0d85d651eeea8dba3c6e2ec0e3859fff92eb9a2[root@yz6205 ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEtest latest 933b24d02ecf About a minute ago 122 MBubuntu latest 7bd023c8937d 41 hours ago 122 MB存入镜像
[root@yz6205 ~]# docker save -o ubuntu_14.04.tar 933b24d02ecf载入镜像
[root@yz6205 ~]# docker load --input ubuntu_14.04.tar 或者:[root@yz6205 ~]# docker load < ubuntu_14.04.tar 查看log信息[root@yz6205 ~]# docker ps -lCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES074b5ad4936f ubuntu "/bin/bash" About a minute ago Exited (0) 44 seconds ago admiring_mccarthy [root@yz6205 ~]# docker logs 074root@074b5ad4936f:/# pwd/root@074b5ad4936f:/# lsbin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr varroot@074b5ad4936f:/# ps PID TTY TIME CMD 1 ? 00:00:00 bash 13 ? 00:00:00 psroot@074b5ad4936f:/# exitexit 终止容器[root@yz6205 ~]# docker stop 074074[root@yz6205 ~]# docker ps -lCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES074b5ad4936f ubuntu "/bin/bash" 5 minutes ago Exited (0) 4 minutes ago admiring_mccarthy [root@yz6205 ~]# docker start 074074[root@yz6205 ~]# docker ps -lCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES074b5ad4936f ubuntu "/bin/bash" 5 minutes ago Up 1 seconds查看处于终止状态下的容器的ID信息
[root@yz6205 ~]# docker ps -a -q074b5ad4936f67156b0cfc7c68dea79aa0795b1280645766d65d3ac7c37410bbf0542e2433e3c46add98dac0735f676731472d1eefcb 重启docker[root@yz6205 ~]# docker restart 074074[root@yz6205 ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES074b5ad4936f ubuntu "/bin/bash" 8 minutes ago Up 9 seconds admiring_mccarthy
-d参数,容器启动后讲进入后台
[root@yz6205 ~]# docker run -idt centos193840bce6de1e26e1263239c7a3fee9c9bb2c8e9b0f43fe0ba4084676e37bfd[root@yz6205 ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES193840bce6de centos "/bin/bash" 48 seconds ago Up 36 seconds sad_albattani可使docket attach 、docket exec 、nsenter等工具查看
[root@yz6205 ~]# docker attach sad_albattani[root@193840bce6de /]#[root@yz6205 ~]# docker exec -ti 193840bce6de /bin/bash
[root@193840bce6de /]#导出容器[root@yz6205 soft]# docker export 193 > 193840bce6de_centos_tar[root@yz6205 soft]# ls193840bce6de_centos_tar
docker登陆注册
[root@yz6205 soft]# docker loginUsername: yongsanPassword: 123qweEmail: yongsan@staff.sina.com.cnWARNING: login credentials saved in /root/.docker/config.jsonAccount created. Please use the confirmation link we sent to your e-mail to activate it.
使用registry创建私有仓库
[root@yz6205 soft]# docker run -d -p 5000:5000 registryUnable to find image 'registry:latest' locallylatest: Pulling from registryf15ce52fc004: Pull complete c4fae638e7ce: Pull complete a4c5be5b6e59: Pull complete 8693db7e8a00: Pull complete c75fbf48538e: Downloading [=======================================> ] 70.28 MB/89.2 MB87c008f1a79b: Download complete 5a7b60cbc471: Download complete 81569492134a: Download complete 0aed6b236dec: Download complete管理私有仓库
docker tag 命令给镜像标记重命名[root@yz6205 soft]# docker tag ubuntu:14.04 10.39.6.205:5000/test[root@yz6205 soft]# docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEtest centos 2a3044c7fb64 58 minutes ago 196.7 MBtest 193840bce6de a753d5365391 59 minutes ago 196.7 MBubuntu latest 7bd023c8937d 43 hours ago 122 MB10.39.6.205:5000/test latest 0e7d4a488bcc 43 hours ago 187.9 MB 下面使用training/webapp 镜像创建一个web容器,并创建一个数据卷挂载到容器的/data0/soft目录[root@yz6205 soft]# docker run -d --name web -v /data0/soft training/webapp python app.pyUnable to find image 'training/webapp:latest' locallylatest: Pulling from training/webappe9e06b06e14c: Pull complete a82efea989f9: Pull complete 37bea4ee0c81: Pull complete 07f8e8c5e660: Pull complete 23f0158a1fbe: Pull complete 0a4852b23749: Pull complete 7d0ff9745632: Pull complete 99b0d955e85d: Pull complete 33e109f2ff13: Pull complete cc06fd877d54: Pull complete b1ae241d644a: Pull complete b37deb56df95: Pull complete 02a8815912ca: Already exists Digest: sha256:06e9c1983bd6d5db5fba376ccd63bfa529e8d02f23d5079b8f74a616308fb11dStatus: Downloaded newer image for training/webapp:latest1c413b58919b2728cabede1639d1a12fa72fe74ab3cfee56a76fdb6ae1bc416a
-p/P指定端口
[root@yz6205 soft]# docker run -d -P training/webapp python app.py48beffc1c93351262ef03c9f65e7f4364e5e6414f3e40bd5db256771f0110102[root@yz6205 dir]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES48beffc1c933 training/webapp "python app.py" 44 seconds ago Up 27 seconds 0.0.0.0:32768->5000/tcp clever_goodall访问宿主机的32768端口即可访问容器内web应用提供的页面了
[root@yz6205 soft]# curl http://10.39.6.205:32768Hello world![root@yz6205 soft]#[root@yz6205 dir]# docker logs -f clever_goodall
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)10.39.6.205 - - [29/May/2016 11:23:47] "GET / HTTP/1.1" 200 -10.212.60.113 - - [29/May/2016 11:24:10] "GET / HTTP/1.1" 200 -10.212.60.113 - - [29/May/2016 11:24:10] "GET /favicon.ico HTTP/1.1" 404 --p可以将本地的5000端口映射到容器的5000端口
[root@yz6205 soft]# docker run -d -p 5000:5000 training/webapp python app.pyb801e4036691e60b0b671883e4b06b8414aef23e495ed2b8cbe7f841c7a8746b[root@yz6205 soft]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESb801e4036691 training/webapp "python app.py" 56 seconds ago Up 35 seconds 0.0.0.0:5000->5000/tcp prickly_yonath