Your First Container

View saved

Start with hello-world

Docker downloads the image if needed, starts a container, prints a message, then exits.

docker run hello-world

Run nginx in the background

The -d flag detaches (runs in the background). --name gives a memorable name. Map host port 8080 to container port 80.

docker run -d --name my-nginx -p 8080:80 nginx

Visit the site

Open http://localhost:8080 in a browser. You should see the default nginx welcome page served from the container.

Use helpful flags

  • --rm remove the container when it exits
  • -it interactive terminal (for shells)
  • -d detach into the background
  • -p host:container publish a port

Comments

One comment per signed-in account. Comments are saved with this page’s URL.