开启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
AWS取得EC2内部IP GET http://169.254.169.254/latest/meta-data/local-ipv4
AWS取得EC2外部IP GET http://169.254.169.254/latest/meta-data/public-ipv4
AWS取得EC2外部IP GET http://169.254.169.254/latest/meta-data/public-ipv4
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
参考链接
https://github.com/Netflix/eureka/issues/937
https://docs.docker.com/engine/api/v1.32/#operation/ContainerInspect
https://docs.docker.com/engine/api/v1.32/#operation/ContainerInspect
备注
Alpin安装CURL
安装GET命令
apk add --update curl
安装GET命令
sudo yum install perl-libwww-perl.noarch
sudo apt-get install libwww-perl