How to rebuild docker container in docker-compose.yml

docker-compose run is supposed to run a container. If the container requires to build an image, the run command also builds the container but it doesn’t have to rebuild the image. docker run does not build either. docker-compose up does everything so you have the option to rebuild.

When you run docker-compose down it doesn’t delete the image. You can delete that manually if you want. When you run docker network rm networkname it deletes the network but not the image. Docker Compose then creates the network because the container needs it but it is not required to rebuild the image which already exists.

I can see in your output that you use Docker Compose v2. V1 would also show you that it creates the container. I guess v2 doesn’t do it because it is obvious (well, I could argue).

So everything seems to work properly.

1 Like