Quantcast
Channel: 看得透又看得远者prevail.ppt.cc/flUmLx ppt.cc/fqtgqx ppt.cc/fZsXUx ppt.cc/fhWnZx ppt.cc/fnrkVx ppt.cc/f2CBVx
Viewing all articles
Browse latest Browse all 20486

在docker容器内获取容器自身的外部端口

$
0
0


开启docker remote api步骤如下

01 开启docker的remote api

需要先设置 remote api 对外暴露 , 但是此处要特别注意 不能让外部访问到.注意防火墙端口权限设置. 不然会被人利用docker remote api任意创建销毁docker容器.
所以ip设置成是172.17.0.1 而不是0.0.0.0 , EC2的私有IP也不行.
#!/bin/bash
cat <<EOF > /etc/sysconfig/docker
OPTIONS="--log-driver=none -H tcp://172.17.0.1:4243 -H unix:///var/run/docker.sock"
EOF
service docker restart
start ecs

02 进入容器内部测试能正常获取container描述. 已经在ECS下验证

curl http://172.17.0.1:4243/v1.24/containers/testport_container/json
curl http://172.17.0.1:4243/v1.24/containers/d5bb394f5410/json

参考链接

备注

Alpin安装CURL
apk add --update curl
安装GET命令
sudo yum install perl-libwww-perl.noarch
sudo apt-get install libwww-perl

Viewing all articles
Browse latest Browse all 20486

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>