Card 02/ 06

WalkthroughDifficulty: Beginner1 min

From an Image to a Page You Can Open

A web server you did not install, serving a page you can open, in three commands.

Running nginx and reaching it from the browser

Step 1 of 4

Start it

bash
$ docker run -d --name web -p 8080:80 nginx
9f2c1b7e4a83

-d leaves it running in the background and prints the container's id. --name web is how you refer to it afterwards instead of typing that id.

Check it is up

bash
$ docker ps --format '{{.Names}}\t{{.Status}}\t{{.Ports}}'
web	Up 4 seconds	0.0.0.0:8080->80/tcp, [::]:8080->80/tcp

Open it

bash
$ curl -s localhost:8080 | head -4
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>

The page is served by a program that is not installed on your machine and never will be.

Stop and remove it

bash
$ docker stop web && docker rm web
web
web

Two steps because they are two things: stopping ends the process, removing discards the container and its writable layer.