Join egghead, unlock knowledge.

Want more egghead? It's 45% off for a limited time only!

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock All Content for 45% Off

Already subscribed? Sign In

Save 45% for a limited time.

Get access to all courses and lessons on egghead today.

Autoplay

    Enter a Docker Container Ran in Detached Mode

    Jacob CarterJacob Carter

    When you run a docker container in detached mode you may want to re-enter that container later. With docker exec you can do that. This short video will show you how!

    dockerDocker
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    Instructor: 00:01 First, we're going to run a Docker container in a detached state. To do that, we'll just type docker run -d, and then the image ID of the Docker image that we want to spin a container off of. Now that we have that container running, we can grab the container ID.

    00:17 Using that container ID, we can reenter that container, so that we can operate from within. To do that, we'll type the command docker exec -it, then the container ID, and then the command that we want to enter into that container with. By typing bash, we will start a Bash session within that container.

    00:37 Now that we're in the container, we can use commands inside of it. For example, I'll list out all the files that are inside this Docker container. These files just represent a mock Node application.

    00:48 When we want to exit out of that Docker container, we simply press control-P-Q, and we will exit that Docker container. That control is going to be control whether you're on a Windows, a Linux, or a Mac. On a Mac, you do not hit the command key. It is always control-P-Q.

    01:06 Now, let's walk through each part of this command. The exec command is what you use to run a command against a Docker container. Specifying a container ID lets Docker know what container you want to run the command against.

    01:21 The command that we want to run against it is bash. That says that we want to start a Bash session of that container. The two flags are really important to give us the terminal-like behavior that we see when we run docker exec -it.

    -01:36 i says that we want access to the SD in stream, which means when I run a command against Bash, I want to see what's returned as a result. The gives us a pseudo TTY. What that basically means is that it's going to give you the driver that you need in order to have terminal-like behavior inside that Docker container.

    01:56 docker exec -it, container ID, bash is a combination of commands and options that give us a terminal-like interface that we can interact with our Docker containers against.

    Discuss

    Discuss