Previous Lecture Complete and continue  

  Run Your First Container

Now that Docker is installed, let's run our first container. Here's the command we'll use.

docker run -it -p 3000:80 nginx

Breaking this command down:

  • docker - the Docker executable, which allows us to manage containers and images
  • run - allows us to run a command in a new container
  • -it - allocates a pseudo-TTY, an interactive bash shell connected to the container.
  • -p 3000:80 - specifies an outward-facing port accessible to the host (localhost) and its corresponding port within the container
    • In this case, nginx runs on port 80, which is exposed within the container. To access it outside the container, we need to publish port 80 and map it to a port outside the container. In this case, we'll use port 3000.
  • nginx - the name of the image we want to run
    • Unless we specify otherwise, this image will be pulled down from Docker Hub, an online repository of images

If you go to http://localhost:3000 or, you should be met with the famous "Welcome to nginx!" page. You're now running a container that runs nginx (pronounced engine-x), a web server! If you check the terminal, you'll also see log output from the nginx.