Home > Software design >  How to stop a Docker image from running?
How to stop a Docker image from running?

Time:02-01

I created a jar file using Spring Boot and created an image from it. Using the following command, I will execute the relevant image and the program will be executed:

docker run -p 8080:8080 81b7afe627db

81b7afe627db is the name of my image.

I can not exit the program using ctrl c while it is running. Using this key combination does not seem to have any effect on the running container. Is there a way for me to stop my program?

CodePudding user response:

Consider two modes: 1- Container attachment 2- Container execution.

You can use -t in your command. In this case, you can use ctrl c to detach your container without stop executing it:

docker run -t -p 8080: 8080 81b7afe627db

Also, if you use -t and -i in your command, then you can terminate the execution of your container:

docker run -it -p 8080: 8080 81b7afe627db

Note: If you use -it and use the ctrl pq key combination, then your container will be detach without termination.

You can use the docker ps command in a separate window to view the status of your containers.

CodePudding user response:

In addition to the accepted answer.

If you start to run docker images as mentioned docker run -p 8080:8080 81b7afe627db. You can follow the following steps to terminate the running container.

  1. Look for running containers name: docker container ls This will list the running containers.

  2. Kill the running container. Select the name of the running container from step 1 and kill the container. docker kill <container-name>

  •  Tags:  
  • Related