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.

1

There are 1 answers

2
Yago Biermann On

you have three main ways to run a command after the container starts:

  1. with docker exec -d someContainer some command from the command line,
  2. with CMD ["some", "command"] from your Dockerfile
  3. 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"]

see this question

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.