1

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
3
  • can u please upload the dockerfile or yaml file whichever u used to up the conatiner Commented Aug 18, 2017 at 7:53
  • 1
    Try enclosing the complete echo redirect in quotes and so "echo $KUBE_ADMIN_ACCOUNT > /opt/application/conf/kubeadminaccount.yml" Commented Aug 18, 2017 at 7:57
  • I would update the way you create the container instead of trying to update it while it's running Commented Aug 18, 2017 at 8:09

1 Answer 1

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"
Sign up to request clarification or add additional context in comments.

2 Comments

Had to add \" around the variable because of the complex value.
Yes that would be needed if value has new lines. But rest now things work for you?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.