Difficulty: Beginner
Estimated Time: 10 minutes

In this lab, we will examine the Docker CLI and execute our first container.

Detached Mode and Exec

Terminal Access

In this lab, we will learn how to interact with an already running Docker container.

  • Run the NGINX image (a web server that services http requests external to the host) and connect to STDIN and a terminal:
    docker container ls
    docker container run -it --rm --name nginx nginx
    ctrl+c to exit.

  • Run the NGINX image in detached mode:
    docker container ls
    docker container run -p 80:80 -d --rm --name nginx nginx
    docker container ls

Notice the port mapping - port 80 in the container has been mapped to port 80 on the host. Go to server https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/ and see the NGINX welcome page.

  • Gain terminal access to detached container:
    docker container exec -it nginx bash
    docker container ls
    docker kill nginx

  • What does the --rm argument do?

  • Why would you want to run commands inside a running container?