3.2 centos6配置Http Api遠(yuǎn)程操作Docker鏡像

目的

配置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


圖片.png

配置方法

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"

圖片.png

網(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

圖片.png

3 瀏覽器訪(fǎng)問(wèn)服務(wù)器的docker
http://xxxxx.com:2375/info
2375端口是你配置的端口欠窒,可以隨便改的
圖片.png

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的


圖片.png
例子:

前提 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"} ]
        }
    }
}
圖片.png

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"
            }
        }
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末丸凭,一起剝皮案震驚了整個(gè)濱河市福扬,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌惜犀,老刑警劉巖铛碑,帶你破解...
    沈念sama閱讀 206,013評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異虽界,居然都是意外死亡汽烦,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,205評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門(mén)莉御,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)撇吞,“玉大人,你說(shuō)我怎么就攤上這事礁叔‰咕保” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 152,370評(píng)論 0 342
  • 文/不壞的土叔 我叫張陵晴圾,是天一觀的道長(zhǎng)颂砸。 經(jīng)常有香客問(wèn)我,道長(zhǎng)死姚,這世上最難降的妖魔是什么人乓? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 55,168評(píng)論 1 278
  • 正文 為了忘掉前任,我火速辦了婚禮都毒,結(jié)果婚禮上色罚,老公的妹妹穿的比我還像新娘。我一直安慰自己账劲,他們只是感情好戳护,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,153評(píng)論 5 371
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著瀑焦,像睡著了一般腌且。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上榛瓮,一...
    開(kāi)封第一講書(shū)人閱讀 48,954評(píng)論 1 283
  • 那天铺董,我揣著相機(jī)與錄音,去河邊找鬼禀晓。 笑死精续,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的粹懒。 我是一名探鬼主播重付,決...
    沈念sama閱讀 38,271評(píng)論 3 399
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼凫乖!你這毒婦竟也來(lái)了确垫?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 36,916評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤帽芽,失蹤者是張志新(化名)和其女友劉穎删掀,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體嚣镜,經(jīng)...
    沈念sama閱讀 43,382評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡爬迟,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,877評(píng)論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了菊匿。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片付呕。...
    茶點(diǎn)故事閱讀 37,989評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖跌捆,靈堂內(nèi)的尸體忽然破棺而出徽职,到底是詐尸還是另有隱情,我是刑警寧澤佩厚,帶...
    沈念sama閱讀 33,624評(píng)論 4 322
  • 正文 年R本政府宣布姆钉,位于F島的核電站,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏潮瓶。R本人自食惡果不足惜陶冷,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,209評(píng)論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望毯辅。 院中可真熱鬧埂伦,春花似錦、人聲如沸思恐。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,199評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)胀莹。三九已至基跑,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間描焰,已是汗流浹背媳否。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,418評(píng)論 1 260
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留栈顷,地道東北人逆日。 一個(gè)月前我還...
    沈念sama閱讀 45,401評(píng)論 2 352
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像萄凤,于是被迫代替她去往敵國(guó)和親室抽。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,700評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容

  • 神說(shuō)要有光靡努,于是便有了光坪圾。 神說(shuō)要有愛(ài),于是便有了愛(ài)惑朦。 神說(shuō)要分離兽泄,于是便留不住一切。 那些希冀美好都是轉(zhuǎn)瞬即逝漾月。...
    楚珺閱讀 260評(píng)論 0 1
  • 上帝在我年幼懵懂的時(shí)候梁肿,為我種下了一棵桃花樹(shù)蜓陌,然后又發(fā)現(xiàn)我是個(gè)傻逼不懂得珍惜,就連根把樹(shù)挖走了吩蔑,以至于現(xiàn)今我還是孤...
    魚(yú)刺S閱讀 254評(píng)論 0 0
  • 架構(gòu)之路(四):測(cè)試驅(qū)動(dòng)-CSDN.NEThttp://www.csdn.net/article/2015-09-...
    葡萄喃喃囈語(yǔ)閱讀 261評(píng)論 0 0