1.docker安装CentOS7 yum install epel-release -yyum install docker -y[root@Docker ~]# docker versionClient: Version: 1.12.6 API version: 1.24 Package version: docker-1.12.6-61.git85d7426.el7.centos.x86_64 Go version: go1.8.3 Git commit: 85d7426/1.12.6 Built: Tue Oct 24 15:40:21 2017 OS/Arch: linux/amd64Server: Version: 1.12.6 API version: 1.24 Package version: docker-1.12.6-61.git85d7426.el7.centos.x86_64 Go version: go1.8.3 Git commit: 85d7426/1.12.6 Built: Tue Oct 24 15:40:21 2017 OS/Arch: linux/amd64[root@Docker ~]# [root@Docker ~]# docker infoContainers: 0 Running: 0 Paused: 0 Stopped: 0Images: 0Server Version: 1.12.6Storage Driver: devicemapper Pool Name: docker-253:0-270443527-pool Pool Blocksize: 65.54 kB Base Device Size: 10.74 GB Backing Filesystem: xfs Data file: /dev/loop0 Metadata file: /dev/loop1 Data Space Used: 11.8 MB Data Space Total: 107.4 GB Data Space Available: 102.8 GB Metadata Space Used: 581.6 kB Metadata Space Total: 2.147 GB Metadata Space Available: 2.147 GB Thin Pool Minimum Free Space: 10.74 GB Udev Sync Supported: true Deferred Removal Enabled: true Deferred Deletion Enabled: true 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. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device. Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata Library Version: 1.02.107-RHEL7 (2015-10-14)Logging Driver: journaldCgroup Driver: systemdPlugins: Volume: local Network: host bridge overlay nullSwarm: inactiveRuntimes: docker-runc runcDefault Runtime: docker-runcSecurity Options: seccompKernel Version: 3.10.0-327.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64Number of Docker Hooks: 3CPUs: 2Total Memory: 1.954 GiBName: localhost.localdomainID: 7NNL:RVYC:M6QY:CP2P:5SNV:3N25:U45I:TUWG:Y4NK:7H4R:CN2B:3E67Docker Root Dir: /var/lib/dockerDebug Mode (client): falseDebug Mode (server): falseRegistry: https://index.docker.io/v1/WARNING: bridge-nf-call-iptables is disabledWARNING: bridge-nf-call-ip6tables is disabledInsecure Registries: 127.0.0.0/8Registries: docker.io (secure)CentOS6 yum install epel-release -yyum install lxc libcgroup device-map* -yyum install docker-io -y[root@Docker ~]# docker versionClient version: 1.7.1Client API version: 1.19Go version (client): go1.4.2Git commit (client): 786b29d/1.7.1OS/Arch (client): linux/amd64Server version: 1.7.1Server API version: 1.19Go version (server): go1.4.2Git commit (server): 786b29d/1.7.1OS/Arch (server): linux/amd64[root@Docker ~]# [root@Docker ~]# docker infoContainers: 0Images: 0Storage Driver: devicemapper Pool Name: docker-253:0-130626-pool Pool Blocksize: 65.54 kB Backing Filesystem: extfs Data file: /dev/loop0 Metadata file: /dev/loop1 Data Space Used: 305.7 MB Data Space Total: 107.4 GB Data Space Available: 11.1 GB Metadata Space Used: 729.1 kB Metadata Space Total: 2.147 GB Metadata Space Available: 2.147 GB Udev Sync Supported: true Deferred Removal Enabled: false Data loop file: /var/lib/docker/devicemapper/devicemapper/data Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata Library Version: 1.02.117-RHEL6 (2016-12-13)Execution Driver: native-0.2Logging Driver: json-fileKernel Version: 2.6.32-431.el6.x86_64Operating System: CPUs: 1Total Memory: 1.834 GiBName: localhost.localdomainID: SKZZ:TYST:LUEG:N66O:364P:7YRG:GQ3W:ODYR:G476:JSHB:I2HF:3A5W说明:docker 默认的存储驱动类型为devicemapper,docker-ce 默认的存储驱动类型为overlay2。2.搜索并下载nginx容器[root@Docker ~]# docker search nginx[root@Docker ~]# docker pull docker.io/nginx3.将容器的80端映射到本机的8080[root@Docker ~]# docker run --name=nginx -itd -p8080:80 docker.io/nginx bash或者[root@Docker ~]# docker run --name nginx -itd -p8080:80 docker.io/nginx /bin/bash 或者[root@Docker ~]# docker run --name=nginx -itd -p8080:80 docker.io/nginx注:--privileged 给予管理员权限,--restart=always 容器随docker宿主机的启动而启动;CentOS7安装服务器后若使用systemctl工具启动创建容器时需要执行/usr/sbin/init或/sbin/init命令。4.查看docker容器进程[root@Docker ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES26ae21c8bddd docker.io/nginx "bash" 5 seconds ago Up 4 seconds 0.0.0.0:8080->80/tcp nginx5.查看docker容器IP地址[root@Docker ~]# docker inspect 0a9db4be695b |grep -i ip "HostIp": "", "IpcMode": "", "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "HostIp": "0.0.0.0", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "IPAMConfig": null, "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0,[root@Docker ~]# 6.浏览器访问测试:http://IP:8080
7.登录进入容器中,更改默认的测试页面内容[root@Docker ~]# docker exec -it 0a9db4be695b /bin/bashroot@0a9db4be695b:/# cd /usr/share/nginx/html/root@0a9db4be695b:/usr/share/nginx/html# ls50x.html index.htmlroot@0a9db4be695b:/usr/share/nginx/html# echo "www.hello.com
"> index.html root@0a9db4be695b:/usr/share/nginx/html# exitexit[root@Docker ~]# 8.浏览器访问测试:http://IP:8080
9.强制删除所有的虚拟机[root@Docker ~]# docker rm -f `docker ps -aq`