docker restart container failed: “already in use”, but there's no more docker image

前端 未结 3 954
长情又很酷
长情又很酷 2021-01-31 15:03

I first got my nginx docker image:

docker pull nginx

Then I started it:

docker run -d -p 80:80 --name webserver nginx
         


        
3条回答
  •  日久生厌
    2021-01-31 15:42

    It is because

    • you have used --name switch.
    • container is stopped and not removed

    You find it stopped

    docker ps -a
    

    You can simply start it using below command:

    docker start webserver
    

    EDIT: Alternatives If you want to start the container with below command each time,

    docker run -d -p 80:80 --name webserver nginx
    

    then use one of the following:

    method 1: use --rm switch i.e., container gets destroyed automatically as soon as it is stopped

    docker run -d -p 80:80 --rm --name webserver nginx
    

    method 2: remove it explicitly after stopping the container before starting the command that you are currently using.

    docker stop 
    docker rm 
    

提交回复
热议问题