原來,Elastic Beanstalk確實只是從任務定義中刪除了特權標誌。您可以通過將其包含在Dockerrun.aws.json文件中來確認此問題,該文件可以在您的應用程序包中上載到EB,然後在aws中進入ECS控制面板,並查看由EB爲您的容器羣集創建的任務定義。特權標誌現在將被設置爲false。這實際上是怪人。
爲了解決這個問題,我不得不花費數小時的時間攻擊一個等待部署來啓動所有容器的ebextension,然後遍歷Dockerrun.aws.json並提取任何應該是的容器定義然後執行docker檢查這些容器的正在運行的非特權版本,然後使用docker檢查中的現有運行配置停止並重新運行它們,但將特權標誌設置爲true。這裏提供了ebextension的文件:https://gist.github.com/therealjessesanford/5a012218889831926169
注意:您不能在Dockerrun.aws.json文件的同一容器定義節中使用essential:true和特權:true。這兩個參數與這個黑客相互排斥。
我還包括他們在這裏內嵌Google員工:
.ebextensions/0001_restart_privileged_containers.config
container_commands:
01-move-restart-hook:
command: cp -f .ebextensions/files/00_restart_containers_with_privileges.sh /opt/elasticbeanstalk/hooks/appdeploy/post/00_restart_containers_with_privileges.sh && chmod 755 /opt/elasticbeanstalk/hooks/appdeploy/post/00_restart_containers_with_privileges.sh
02-move-stop-hook:
command: cp -f .ebextensions/files/02stop_privileged_containers.sh /opt/elasticbeanstalk/hooks/appdeploy/pre/02stop_privileged_containers.sh && chmod 755 /opt/elasticbeanstalk/hooks/appdeploy/pre/02stop_privileged_containers.sh
.ebextensions /文件/ 00_restart_containers_with_privileges。SH
#!/bin/bash
set -ex
. /opt/elasticbeanstalk/hooks/common.sh
EB_CONFIG_APP_STAGING=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
export DOCKERRUN_AWS_JSON=$EB_CONFIG_APP_STAGING/Dockerrun.aws.json
while read -r container_short_name; do
CURRENT_CONTAINER_ID=$(docker ps --no-trunc -q --filter=name=.$container_short_name)
CONTAINER_LONG_NAME=$(docker inspect --format='{{.Name}}' $CURRENT_CONTAINER_ID)
CURRENT_CONFIG=$(docker inspect --format='{{json .Config}}' $CURRENT_CONTAINER_ID)
NEW_HOST_CONFIG=$(docker inspect --format='"HostConfig":{{json .HostConfig}}' $CURRENT_CONTAINER_ID | sed 's/\"Privileged\":false/\"Privileged\":true/I')
echo "Stopping unprivileged $CONTAINER_LONG_NAME"
docker stop $CURRENT_CONTAINER_ID
docker rm $CURRENT_CONTAINER_ID
NEW_CONTAINER_ID=$(curl --unix-socket /var/run/docker.sock -X POST -H "Content-Type: application/json" http:/containers/create?name=$CONTAINER_LONG_NAME -d "${CURRENT_CONFIG%?},$NEW_HOST_CONFIG}" | jq -r '.Id')
echo "Starting privileged $CONTAINER_LONG_NAME"
docker start $NEW_CONTAINER_ID
sed -i "s/$CURRENT_CONTAINER_ID/$NEW_CONTAINER_ID/g" /var/lib/ecs/data/ecs_agent_data.json
done <<< "$(jq -r '.containerDefinitions[] | select(.privileged == true) | .name' $DOCKERRUN_AWS_JSON)"
.ebextensions /文件/ 02stop_priviliged_containers.sh
#!/bin/bash
set -ex
. /opt/elasticbeanstalk/hooks/common.sh
EB_CONFIG_APP_CURRENT=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
export DOCKERRUN_AWS_JSON=$EB_CONFIG_APP_CURRENT/Dockerrun.aws.json
while read -r container_short_name; do
CURRENT_CONTAINER_ID=$(docker ps -q --filter=name=.$container_short_name)
if [[ ! -z $CURRENT_CONTAINER_ID && "FOOBAR$CURRENT_CONTAINER_ID" != "FOOBAR" ]]; then
CONTAINER_LONG_NAME=$(docker inspect --format='{{.Name}}' $CURRENT_CONTAINER_ID)
echo "Stopping unprivileged $CONTAINER_LONG_NAME"
docker stop $CURRENT_CONTAINER_ID || true
docker rm $CURRENT_CONTAINER_ID || true
fi
done <<< "$(jq -r '.containerDefinitions[] | select(.privileged == true) | .name' $DOCKERRUN_AWS_JSON)"
./Dockerrun.aws.json
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"name": "happy_container_name",
"image": "tutum.co/happy/happy_container",
"memory": 128,
"essential": false,
"privileged": true
}
]
}