由于我们希望使用squash
来减小图像大小,因此我们试图在github工作流上的ubuntu最新图像上启用实验功能。但是,这是不可能的,因为我们收到以下错误:
/home/runner/work/_temp/59d363d1-0231-4d54-bffe-1e3205bf6bf3.sh:行 3:/etc/docker/daemon.json:权限被拒绝
用于以下工作流程:
- name: Build, tag, and push TOING image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: TOING/TOING/TOING_REPO
IMAGE_TAG: TOING_TEST
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
#build and push images
sudo rm -rf /etc/docker/daemon.json
sudo echo '{"experimental": true}' >> /etc/docker/daemon.json
sudo systemctl restart docker
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f core/TOING/Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
我们已验证daemon.json文件已正确更新,并且还对命令使用了sudo,如图所示。
我们也为此打开了issue on github,但到目前为止没有任何回应。我将不胜感激。
PS :我们已经尝试了“ experimental": true
和"experimental": "enabled"
。
答案 0 :(得分:1)
我们已验证daemon.json文件已正确更新
根据您的错误消息,它似乎未正确更新 :
/home/runner/work/_temp/59d363d1-0231-4d54-bffe-1e3205bf6bf3.sh:行 3:/etc/docker/daemon.json:权限被拒绝
这是怎么回事?好吧,sudo
命令将以root
的身份运行给定命令。但是,您正在执行shell重定向,它是由shell本身而不是sudo
处理的。换句话说,您正在重定向 sudo的输出。
如果您要以根用户身份写入文件 ,则实际上需要run a command that writes the file, and then run that using sudo。例如:
echo '{"experimental": true}' | sudo tee -a /etc/docker/daemon.json