CentOS7 部署docker
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 1.docker安装 CentOS7 yum install epel-release-y yum install docker-y [root@Docker~] #dockerversion Client: Version:1.12.6 APIversion:1.24 Packageversion:docker-1.12.6-61.git85d7426.el7.centos.x86_64 Goversion:go1.8.3 Gitcommit:85d7426 /1 .12.6 Built:TueOct2415:40:212017 OS /Arch :linux /amd64 Server: Version:1.12.6 APIversion:1.24 Packageversion:docker-1.12.6-61.git85d7426.el7.centos.x86_64 Goversion:go1.8.3 Gitcommit:85d7426 /1 .12.6 Built:TueOct2415:40:212017 OS /Arch :linux /amd64 [root@Docker~] # [root@Docker~] #dockerinfo Containers:0 Running:0 Paused:0 Stopped:0 Images:0 ServerVersion:1.12.6 StorageDriver:devicemapper PoolName:docker-253:0-270443527-pool PoolBlocksize:65.54kB BaseDeviceSize:10.74GB BackingFilesystem:xfs Data file : /dev/loop0 Metadata file : /dev/loop1 DataSpaceUsed:11.8MB DataSpaceTotal:107.4GB DataSpaceAvailable:102.8GB MetadataSpaceUsed:581.6kB MetadataSpaceTotal:2.147GB MetadataSpaceAvailable:2.147GB ThinPoolMinimumFreeSpace:10.74GB UdevSyncSupported: true DeferredRemovalEnabled: true DeferredDeletionEnabled: true DeferredDeletedDeviceCount:0 Dataloop file : /var/lib/docker/devicemapper/devicemapper/data WARNING:Usageofloopbackdevicesisstronglydiscouraged for productionuse.Use`--storage-optdm.thinpooldev`tospecifyacustomblockstoragedevice. Metadataloop file : /var/lib/docker/devicemapper/devicemapper/metadata LibraryVersion:1.02.107-RHEL7(2015-10-14) LoggingDriver:journald CgroupDriver:systemd Plugins: Volume: local Network:hostbridgeoverlaynull Swarm:inactive Runtimes:docker-runcrunc DefaultRuntime:docker-runc SecurityOptions:seccomp KernelVersion:3.10.0-327.el7.x86_64 OperatingSystem:CentOSLinux7(Core) OSType:linux Architecture:x86_64 NumberofDockerHooks:3 CPUs:2 TotalMemory:1.954GiB Name:localhost.localdomain ID:7NNL:RVYC:M6QY:CP2P:5SNV:3N25:U45I:TUWG:Y4NK:7H4R:CN2B:3E67 DockerRootDir: /var/lib/docker DebugMode(client): false DebugMode(server): false Registry:https: //index .docker.io /v1/ WARNING:bridge-nf-call-iptablesisdisabled WARNING:bridge-nf-call-ip6tablesisdisabled InsecureRegistries: 127.0.0.0 /8 Registries:docker.io(secure) CentOS6 yum install epel-release-y yum install lxclibcgroupdevice-map*-y yum install docker-io-y [root@Docker~] #dockerversion Clientversion:1.7.1 ClientAPIversion:1.19 Goversion(client):go1.4.2 Gitcommit(client):786b29d /1 .7.1 OS /Arch (client):linux /amd64 Serverversion:1.7.1 ServerAPIversion:1.19 Goversion(server):go1.4.2 Gitcommit(server):786b29d /1 .7.1 OS /Arch (server):linux /amd64 [root@Docker~] # [root@Docker~] #dockerinfo Containers:0 Images:0 StorageDriver:devicemapper PoolName:docker-253:0-130626-pool PoolBlocksize:65.54kB BackingFilesystem:extfs Data file : /dev/loop0 Metadata file : /dev/loop1 DataSpaceUsed:305.7MB DataSpaceTotal:107.4GB DataSpaceAvailable:11.1GB MetadataSpaceUsed:729.1kB MetadataSpaceTotal:2.147GB MetadataSpaceAvailable:2.147GB UdevSyncSupported: true DeferredRemovalEnabled: false Dataloop file : /var/lib/docker/devicemapper/devicemapper/data Metadataloop file : /var/lib/docker/devicemapper/devicemapper/metadata LibraryVersion:1.02.117-RHEL6(2016-12-13) ExecutionDriver:native-0.2 LoggingDriver:json- file KernelVersion:2.6.32-431.el6.x86_64 OperatingSystem:<unknown> CPUs:1 TotalMemory:1.834GiB Name:localhost.localdomain ID:SKZZ:TYST:LUEG:N66O:364P:7YRG:GQ3W:ODYR:G476:JSHB:I2HF:3A5W 说明:docker默认的存储驱动类型为devicemapper,docker-ce默认的存储驱动类型为overlay2。 2.搜索并下载nginx容器 [root@Docker~] #dockersearchnginx [root@Docker~] #dockerpulldocker.io/nginx 3.将容器的80端映射到本机的8080 [root@Docker~] #dockerrun--name=nginx-itd-p8080:80docker.io/nginxbash 或者 [root@Docker~] #dockerrun--namenginx-itd-p8080:80docker.io/nginx/bin/bash 或者 [root@Docker~] #dockerrun--name=nginx-itd-p8080:80docker.io/nginx 注:--privileged给予管理员权限,--restart=always容器随docker宿主机的启动而启动;CentOS7安装服务器后若使用systemctl工具启动创建容器时需要执行 /usr/sbin/init 或 /sbin/init 命令。 4.查看docker容器进程 [root@Docker~] #dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES 26ae21c8bddddocker.io /nginx "bash" 5secondsagoUp4seconds0.0.0.0:8080->80 /tcp nginx 5.查看docker容器IP地址 [root@Docker~] #dockerinspect0a9db4be695b|grep-iip "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 1 2 3 4 5 6 7 8 9 10 11 12 7.登录进入容器中,更改默认的测试页面内容 [root@Docker~] #dockerexec-it0a9db4be695b/bin/bash root@0a9db4be695b:/ #cd/usr/share/nginx/html/ root@0a9db4be695b: /usr/share/nginx/html #ls 50x.htmlindex.html root@0a9db4be695b: /usr/share/nginx/html #echo"<h1>www.hello.com</h1>">index.html root@0a9db4be695b: /usr/share/nginx/html #exit exit [root@Docker~] # 8.浏览器访问测试: http: //IP :8080 1 2 9.强制删除所有的虚拟机 [root@Docker~] #dockerrm-f`dockerps-aq` 本文转自 dengaosky 51CTO博客,原文链接:http://blog.51cto.com/dengaosky/2045168,如需转载请自行联系原作者