Docker Community Forums

Share and learn in the Docker community.

Run commands after docker container started?

docker

#1

I have a build where I’m trying to do just a few things (copy over some directories, remove some existing directories that are created in the container by default).

I’ve got it where it builds fine using docker-compose up

But how do I run commands on that container after it’s up?

In my dockerfile I put:
RUN mkdir /var/www/html/wp-content/themes/test_theme/

But it fails saying ‘no such file or directory’, which is true - because I’m trying to make that directory.

So how would I accomplish something like that?


#2

I’ve got it sorted.

I was missing a few commands prior to that command running.


#3

Even though you resolved your immediate issue, it’s helpful to know that

docker container exec [OPTIONS] CONTAINER COMMAND [ARG...]

Can invoke commands on running containers. If you want to modify an image, you have to use
docker run IMAGE COMMAND
And then
docker container commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
to create a new image.