0

I have dockerfile

CMD [ "/run/myfile.sh" ]

I build it

docker build . -t myRepo/test/my-app:1.0.0

and run it

docker run -it --rm myRepo/test/my-app:1.0.0 sh 

If I want to change the CMD with more parameters How I can do it ? for example I want to create folder

   command: ["/bin/sh"]
    args: [ "-c", "mkdir -p /myfolder/sub && mkdir -p /myfolder2/sub2"]

I tried

docker run -it --rm myRepo/test/my-app:1.0.0 sh [ "-c", "mkdir -p /myfolder/sub && mkdir -p /myfolder2/sub2"]
user1365697
  • 5,819
  • 15
  • 60
  • 96
  • You already overrode the value of `CMD` with the `sh` at the end of your `docker run` command. JSON syntax doesn't work on the command line, just enter it as you would on the command line, same as if you weren't in a container. – BMitch Jun 13 '19 at 14:04
  • Possible duplicate of [docker run ](https://stackoverflow.com/questions/28490874/docker-run-image-multiple-commands) – Nick Muller Jun 13 '19 at 15:14

1 Answers1

1

If you need to run multiple commands, try to use entrypoint.sh

Just create a shell script, for example:

#!/bin/sh
mkdir -p /foo/bar
mkdir -p /foo2/bar2
#whatever

And edit your Dockerfile:

COPY entrypoint.sh /usr/local/bin/

CMD ["entrypoint.sh"]

But I'm not sure it's your case, creating directories are better in RUN commands, not CMD:

FROM centos:7

RUN mkdir -p /foo/bar/ && mkdir -p /foo2/bar2/
RUN ...
COPY entrypoint.sh /usr/local/bin/
CMD ["entrypoint.sh"]
Viktor Khilin
  • 1,760
  • 9
  • 21