0

Here is a portion of my shell script:

...
docker exec -it graphite bash
cd /opt/graphite/conf
echo >> storage-schemas.conf
echo "[atlas]" >> storage-schemas.conf
echo "pattern = test.atlas" >> storage-schemas.conf
echo "retentions = 1s:15d,10s:45d" >> storage-schemas.conf
...

I want to bash into a running docker container (called graphite), then cd into /opt/graphite/conf then append a few lines of text to a file called storage-schemas.conf. But when I run the above shell script, it creates a new file storage-schemas.conf on my desktop (which is my working directory) and appends to that!

I know I'm not using cd command correctly as this post here explains. But I really need my shell script to not have any dependency, as the end goal is to provide a one-click solution across many teams. Is there a way?

singh2005
  • 1,251
  • 12
  • 19
  • 2
    your cd/echo commands are running as part of the main bash script, and will only run AFTER the docker command has finished/exited. you need to put those cd/echos into their OWN shell script, and tell docker to execute it inside the container. – Marc B Aug 20 '15 at 14:24
  • Yes! Thank you Marc! I too realized this that my shell script pauses after running the docker command, and only after I manually exit the docker container (type 'exit' then hit enter), does my remainder of shell script execute. Now let me try to figure out how to tell docker to execute a shell script inside the container. – singh2005 Aug 20 '15 at 14:45

1 Answers1

0

So it turns out that the work-around for this problem was fairly simple. Instead of entering inside the docker container and then trying to append a file, I'm now copying the file from host and pasting(overwriting) it inside the docker container. I can achieve this easily using the docker cp command and I don't have to leave my main bash script (Thanks again Marc for pointing this out).

Community
  • 1
  • 1
singh2005
  • 1,251
  • 12
  • 19