Skip to content
rajin

Docker: Your First Container

Preview~15 min3 steps

This sandbox runs its own Docker engine, isolated from everything else. You will run a web server, call it and build your own image.

The images nginx:alpine, alpine and busybox are pre-loaded, because this sandbox has no internet access.

Steps

The sandbox is not running. Launch it to insert commands and verify steps; reading and predicting work without it.

  1. 01Run nginx in the background

    Start nginx:alpine detached (-d), name it web-demo and publish container port 80 on port 8080 (-p 8080:80).

    • docker run -d --name web-demo -p 8080:80 nginx:alpine
    • docker ps
  2. 02Call your container

    Send a request to port 8080, then save the response to ~/workspace/response.html. You should see the nginx welcome page.

    • curl http://localhost:8080
    • curl -s http://localhost:8080 -o ~/workspace/response.html
  3. 03Build your own image

    A Dockerfile is waiting in ~/workspace/docker-lab. Build it into an image tagged my-app:v1.

    • cat ~/workspace/docker-lab/Dockerfile
    • docker build -t my-app:v1 ~/workspace/docker-lab
    • docker images my-app