I just want to rename a few files, without overriding the commands inside the wordpress image that the docker is pulling in. Inside the docker-compose.yml I tried using 'command' and 'entrypoint' to run bash commands, both basically interrupt what's happening inside the image and it all fails.
-
1use exec on on the running container. https://docs.docker.com/engine/reference/commandline/exec/. But keep in mind that the changes wont be permanent. – The Fool Apr 07 '22 at 18:03
-
That doesn't work for me, I need it to run as a part of 'docker compose up' – Mladen Apr 07 '22 at 18:05
-
then you need to use the entrypoint and at the end of your entrypoint call the original entrypoint or command. – The Fool Apr 07 '22 at 18:07
-
How do I call the original entrypoint? – Mladen Apr 07 '22 at 18:07
-
1you can inspect the image. `docker inspect -f '{{.Config.Entrypoint}}'
` – The Fool Apr 07 '22 at 18:09 -
If it doesnt have an entrypoint just do an `exec "$@"` at the end of your entrypoint. It will basically call the CMD since this is passed as args to the entrypoint. – The Fool Apr 07 '22 at 18:11
-
respectivly you may also want to call the original entrypoint and pass the command as args. You need to check how it exactly is setup. – The Fool Apr 07 '22 at 18:12
1 Answers
you have three main ways to run a command after the container starts:
- with
docker exec -d someContainer some command
from the command line, - with
CMD ["some", "command"]
from your Dockerfile - with
command: some command
from a docker-compose file
if none of these is working for you, probably, you are doing something wrong. A common mistake is using multiple command
in your docker-compose file, like so:
version: '3.8'
services:
someService:
command: a command
command: another command
this doesn't work, because the last command overrides the commands above, what you should do is concatenate the commands:
version: '3.8'
services:
someService:
command: a command && another command
take a look at this question.
edit: one thing i forgot to include is that the same behavior above is true to CMD in your Dockerfile, you can't do this:
CMD ["some", "command"]
CMD ["another", "command"]
instead, you should concatenate the commands, just like the docker-compose:
CMD ["some", "command", "&&", "another", "command"]
but this is very boring if you have a lot of commands, so an alternative is to use a shell script with all the commands you need and execute it in your Dockerfile:
#!/bin/sh
# bash file with your commands
run wordpress && rename files && do something else
# later in your Dockerfile
CMD ["sh", "/path/to/file.sh"]
As you haven't provided any code it's hard to say, but also, maybe you can use RUN command to rename
as the last command(just before the CMD if you are using it) in your Dockerfile to rename these files at build time(what IMHO makes more sense because this is kind of thing you should do when you are building your images). So if you want more help, please, include your code too.

- 1,494
- 1
- 7
- 20
-
3These methods you described will not override the CMD or ENTRYPOINT in the image docker is pulling in? That was my main requirement – Mladen Apr 08 '22 at 11:33
-
1Of course, if don't work i recommend to include your code in the question, because probably you are doing something wrong – Yago Biermann Apr 08 '22 at 22:05