File not found in Docker Container using GitLab-CI

2019-08-13 18:42发布

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条回答
来,给爷笑一个
2楼-- · 2019-08-13 19:09

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"
查看更多
登录 后发表回答