Run, Stop and Remove Docker Containers

Mark Shust
InstructorMark Shust
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 2 years ago

In this lesson, we'll find out the basics of running Docker containers. We'll go over how to download images from Docker Hub, what happens when you stop containers, how to restart a container once it's been stopped, and also how to remove containers.

[00:00] There are two ways to run Docker containers. Type a simple Docker run command, followed by the name of the image you want to run, in this case, mongo.

[00:09] The container will download from Docker hub if it does not currently exist on your machine. If it does exist, it will pull the image right from your downloaded image cache. The Docker run command will run the container in the foreground and all logs will be outputted to the terminal.

[00:25] Type control-C to stop the container, another way to run the containers is to specify the -d flag, which runs the container as a background daemon. We can check to see which containers are currently running by typing docker ps. To stop a container, type docker stop, followed by the container ID. Let's verify there are no containers running.

[00:47] Just because we stopped a container, doesn't mean it no longer exists. It will remain at a stop or exited state. We can see all containers regardless of status by typing docker ps -a. We can start a container again by typing docker start and then the container ID.

[01:04] Note that you don't need to use the full ID, but just the first few letters, as long as it has uniqueness among the other downloaded image IDs. Let's check to see that the container is indeed running again.

[01:17] To remove a container, type docker rm and the container ID. Note that containers need to be stopped in order for them to be able to be removed. Let's go ahead and stop and remove this running container. Then we can verify all containers have been removed.

egghead
egghead
~ 3 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today