I have a docker container based on an image that, by default, does not run any command when started. I need to execute a command in that container.
Running docker run -it [container tag]
runs, but there are two problems:
- It runs in interactive mode (as one would expect), while I need something that can run on a server, without human supervision.
- I need to perform a
docker cp
commands before executing the command I need to run.
Basically, what I have is:
docker create
creates the container.docker cp
moves over the files I need.docker start
starts the container, but since it has no default command to run, it exits immediately.docker exec
refuses to run my command, because the container is stopped. No amount ofdocker start
can fix this.
I cannot edit the image Dockerfile, so unfortunately, adding a while true; done
(suggested here) as default command to run isn't possible.
I assumed a command that would chain start
and exec
back-to-back (and ensure the container doesn't close before the command is run, similar to how run
is create
-start
-attach
) would be already existing, but I can't seem to find anything neither in the documentation nor in other forum answers.