问题
Using GitLab-CI, I am attempting to echo a secret variable into a file inside a Docker container. The file exists and the user has permissions to write to the file yet I get a No such file or directory error.
$ /usr/bin/docker exec -t $CI_PROJECT_NAME ls -la /opt/application/conf/kubeadminaccount.yml
-rw-rw-r-- 1 nodeuser nodeuser 420 Aug 18 07:19 /opt/application/conf/kubeadminaccount.yml
$ /usr/bin/docker exec -t $CI_PROJECT_NAME whoami
nodeuser
$ /usr/bin/docker exec -t $CI_PROJECT_NAME echo $KUBE_ADMIN_ACCOUNT > /opt/application/conf/kubeadminaccount.yml
bash: line 69: /opt/application/conf/kubeadminaccount.yml: No such file or directory
回答1:
Your redirection operator is working on host and not inside your container. Change below
$ /usr/bin/docker exec -t $CI_PROJECT_NAME echo $KUBE_ADMIN_ACCOUNT > /opt/application/conf/kubeadminaccount.yml
to
$ /usr/bin/docker exec -t $CI_PROJECT_NAME bash -c "echo $KUBE_ADMIN_ACCOUNT > /opt/application/conf/kubeadminaccount.yml"
来源:https://stackoverflow.com/questions/45751331/file-not-found-in-docker-container-using-gitlab-ci