2

What are the commands to totally destroy a docker container, but then still be able to build it again using docker up?

I don’t want to just take it down with docker down, but I want to destroy it totally so it becomes rebuilt when running up again.

2 Answers 2

1

To remove and rebuild a docker container do the following.

First, get the container id (or name):

docker container ls -a

Now you can remove/destroy the container(s) by running:

docker container rm container_id

Or for multiple containers

docker container rm container_id1 container_id2 ...

Now you can rebuild it with:

docker-compose up --build

Or for a specific configuration

docker-compose -f docker-compose-file.yml up --build

--build may not be needed as it will be the default when it has been destroyed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.