目的
配置docker所在的服務(wù)器田巴,使得可通過(guò)http遠(yuǎn)程訪(fǎng)問(wèn)操作服務(wù)器docker
環(huán)境
Linux:CentOS release 6.10 (Final)
docker: 1.7
環(huán)境很重要,CentOS 6和CentOS 7的配置文件路徑是不一樣的卖鲤,有些配置文件找不到蒂教,配置也不一樣N【佟!凝垛!
本篇說(shuō)的是CentOS6
配置方法
1修改配置文件/etc/sysconfig/docker里的配置
vim /etc/sysconfig/docker
把原來(lái)的other_args=
改為
other_args="-H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375"
網(wǎng)上說(shuō)的啥配置DOCKER_OPTS="-H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375"的都沒(méi)用
2 重啟docker使配置生效
service docker restart
即使此時(shí)你有docker鏡像正在運(yùn)行懊悯,也可以重啟docker的,不影響苔严,不會(huì)把你正在運(yùn)行的docker斷掉的
檢查下2375端口是不是在監(jiān)聽(tīng)狀態(tài)定枷,有就對(duì)了,外網(wǎng)訪(fǎng)問(wèn)届氢,防火墻注意下
netstat -nap | grep 2375
3 瀏覽器訪(fǎng)問(wèn)服務(wù)器的docker
http://xxxxx.com:2375/info
2375端口是你配置的端口欠窒,可以隨便改的
HTTP API 如何創(chuàng)建鏡像?
官網(wǎng)API:https://docs.docker.com/engine/api/v1.29/#section/Versioning
1.25版本之后的api樣式和原來(lái)不一樣了退子,最新的更好看點(diǎn)
docker版本與api版本對(duì)應(yīng)關(guān)系
我應(yīng)該用1.26的
例子:
前提 Content-Type: application/json
1創(chuàng)建容器
POST /containers/create
創(chuàng)建鏡像其實(shí)主要是配置HostConfig
配置10000端口映射docker內(nèi)部的8080端口岖妄,得配ExposedPorts屬性
配置掛載目錄/tmp:/tmp,后面是docker內(nèi)部的目錄寂祥,且必須都是絕對(duì)路徑
官方解釋?zhuān)篽ost-src:container-dest to bind-mount a host path into the container. Both host-src, and container-dest must be an absolute path.
{
"MemorySwap": 0,
"AttachStdin": false,
"AttachStdout": true,
"AttachStderr": true,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": null,
"Image": "docker.io/tomcat:latest",
"WorkingDir": "",
"ExposedPorts": {"8080/tcp": { }},
"HostConfig": {
"Binds": ["/test:/usr/local/tomcat/logs"],
"PortBindings": {
"8080/tcp": [ {"HostPort": "5005"} ]
}
}
}
2容器重命名
我在創(chuàng)建的時(shí)候沒(méi)找到直接命名的參數(shù)荐虐,所以只能先創(chuàng)建,再重命名
POST
http://192.168.0.243:2375/v1.13/containers/658b5801d60ecd4dd1fc2a9416bbdf626f6fbac5f20db432c910e01dd41e2d30/rename?name=tomcat5000
3查看容器詳情
GET
http://192.168.0.243:2375/v1.25/containers/tomcat5000/json
結(jié)果
{
"Id": "98a9ae018a03b471be2c1415498f876c461beedb9d3d703bd61330be374aa742",
"Created": "2018-11-12T08:08:28.47363772Z",
"Path": "catalina.sh",
"Args": [
"run"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 22403,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-11-12T08:19:58.858983084Z",
"FinishedAt": "2018-11-12T08:19:44.6429067Z"
},
"Image": "sha256:6759d91a032b85a78353424a993101154f9696ced5be11718dd52879efc7e1c1",
"ResolvConfPath": "/var/lib/docker/containers/98a9ae018a03b471be2c1415498f876c461beedb9d3d703bd61330be374aa742/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/98a9ae018a03b471be2c1415498f876c461beedb9d3d703bd61330be374aa742/hostname",
"HostsPath": "/var/lib/docker/containers/98a9ae018a03b471be2c1415498f876c461beedb9d3d703bd61330be374aa742/hosts",
"LogPath": "",
"Name": "/tomcat5000",
"RestartCount": 0,
"Driver": "overlay2",
"MountLabel": "system_u:object_r:svirt_sandbox_file_t:s0:c29,c330",
"ProcessLabel": "system_u:system_r:svirt_lxc_net_t:s0:c29,c330",
"AppArmorProfile": "",
"ExecIDs": [
"7d7d6cf51d1f617bb886b29eccb20f74b05fe440f3365821b29af27b01a1ef22"
],
"HostConfig": {
"Binds": [
"/tmp/host:/tmp"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "journald",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"8080/tcp": [
{
"HostIp": "",
"HostPort": "5000"
}
]
},
"RestartPolicy": {
"Name": "",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "docker-runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": -1,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
},
"GraphDriver": {
"Name": "overlay2",
"Data": {
"LowerDir": "/var/lib/docker/overlay2/994e4c62e3f7af2704a350919bd6f652e4c808e0ce606bfc6dae77106ab468b2-init/diff:/var/lib/docker/overlay2/69303a74ba91199bff3d6a17831546adfc71a0aa32b7ea02e7ba691447eedd11/diff:/var/lib/docker/overlay2/9869e4fecbbf57601ce760a67512cc311fe5298a8e5cd171a6a849f4d04442c2/diff:/var/lib/docker/overlay2/740c060abf34f68fdde4b35ed64982a82d107b07f28dd3f681338bbe91dc64a9/diff:/var/lib/docker/overlay2/496ca9d192609293b1df2ba09dac3377dccd913b8af74f15340069d0b6b3eb57/diff:/var/lib/docker/overlay2/f38bc8eac5ef46af0b6298f73b8edb00eae2af0e90aa5ba4825a1ffca7f0a2ba/diff:/var/lib/docker/overlay2/9b3290aa7995d85837d0d85289a3077b5c01bae8f8c1a68372357c2d2bc71834/diff:/var/lib/docker/overlay2/2452ecb6e9842120fc7fe97903958ae0004ebdd805102fe5ee355896f191fd7b/diff:/var/lib/docker/overlay2/ce4c281daa1108a05497308f0f65cd7830b46d0d64dffcc2ea950c9d78631e3f/diff:/var/lib/docker/overlay2/38263d4aaa05e7505be072e05536e9aa24a03def6d1683a02c8a2feba37bf897/diff:/var/lib/docker/overlay2/0b18831500fdbb182dfb7025d30e3ce0e20e949e4fe99eb31b0ec54d726b2ad4/diff:/var/lib/docker/overlay2/59871599bdc603e0a002cfbb9759114f4c086321fb1f51bd73507a67d0c947dc/diff:/var/lib/docker/overlay2/7b1f5da7a77d77eb3f49f5117d3c1f52819b957ca2e448ef8db83e52b1848463/diff",
"MergedDir": "/var/lib/docker/overlay2/994e4c62e3f7af2704a350919bd6f652e4c808e0ce606bfc6dae77106ab468b2/merged",
"UpperDir": "/var/lib/docker/overlay2/994e4c62e3f7af2704a350919bd6f652e4c808e0ce606bfc6dae77106ab468b2/diff",
"WorkDir": "/var/lib/docker/overlay2/994e4c62e3f7af2704a350919bd6f652e4c808e0ce606bfc6dae77106ab468b2/work"
}
},
"Mounts": [
{
"Type": "bind",
"Source": "/tmp/host",
"Destination": "/tmp",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
"Config": {
"Hostname": "98a9ae018a03",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": true,
"AttachStderr": true,
"ExposedPorts": {
"8080/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/tomcat/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=C.UTF-8",
"JAVA_HOME=/docker-java-home/jre",
"JAVA_VERSION=8u181",
"JAVA_DEBIAN_VERSION=8u181-b13-2~deb9u1",
"CA_CERTIFICATES_JAVA_VERSION=20170531+nmu1",
"CATALINA_HOME=/usr/local/tomcat",
"TOMCAT_NATIVE_LIBDIR=/usr/local/tomcat/native-jni-lib",
"LD_LIBRARY_PATH=/usr/local/tomcat/native-jni-lib",
"OPENSSL_VERSION=1.1.0f-3+deb9u2",
"GPG_KEYS=05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5 541FBE7D8F78B25E055DDEE13C370389288584E7 61B832AC2F1C5A90F0F9B00A1C506407564C17A3 713DA88BE50911535FE716F5208B0AB1D63011C7 79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED 9BA44C2621385CB966EBA586F72C284D731FABEE A27677289986DB50844682F8ACB77FC2E86E29AC A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23",
"TOMCAT_MAJOR=8",
"TOMCAT_VERSION=8.5.35",
"TOMCAT_SHA512=1084c067eec2bd27ed2aa5a3729cdc27d0beddbc41968a7004754e75dd88a6703f5fc0e3a01f262cfe2b5d13ed58c95dca1c43bc5ae8789141a11e11f72edd89",
"TOMCAT_TGZ_URLS=https://www.apache.org/dyn/closer.cgi?action=download&filename=tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz \thttps://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz \thttps://www.apache.org/dist/tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz \thttps://archive.apache.org/dist/tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz",
"TOMCAT_ASC_URLS=https://www.apache.org/dyn/closer.cgi?action=download&filename=tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz.asc \thttps://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz.asc \thttps://www.apache.org/dist/tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz.asc \thttps://archive.apache.org/dist/tomcat/tomcat-8/v8.5.35/bin/apache-tomcat-8.5.35.tar.gz.asc"
],
"Cmd": [
"catalina.sh",
"run"
],
"ArgsEscaped": true,
"Image": "docker.io/tomcat:latest",
"Volumes": null,
"WorkingDir": "/usr/local/tomcat",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "35d58d9a4a82884baea1244f267d6998702425a45f079ffaed93c5130bfd8ebb",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"8080/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "5000"
}
]
},
"SandboxKey": "/var/run/docker/netns/35d58d9a4a82",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "9ce27842046872561e33f1b188da5191abfbd6c07804b10b6b15e7b63f2de91f",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.4",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:04",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "c6bf9dd1099213784a17d2b3d3dbb88d8a0b141f34300a15e7096b066e507b9b",
"EndpointID": "9ce27842046872561e33f1b188da5191abfbd6c07804b10b6b15e7b63f2de91f",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.4",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:04"
}
}
}
}