DOCKER - 5 5 Solution Exercise volume name

For this lesson you'll build your own image from a Dockerfile. You'll walk through the file line by line and make it work yourself. Creating custom images and helping other developers dockerize their code is a common Docker admin task. Often you'll dig through an official image and the README of a piece of software you don't know that well, and still produce a working container.

Dockerizing a Node.js app

This task: take an existing Node.js web app and turn it into a Docker image. You don't need to know Node — only that it's a web app. Your job is to write a Dockerfile, build it, test it in a container, push it to Docker Hub, remove the local copy, then re-run it from the registry to prove the round trip works. We start from the official Node image on Docker Hub, which has good docs, and we pick the Alpine variant because it's tiny. Pin to Node 6.x (any tag under the 6 branch).

The expected outcome: open the app on localhost in your browser and see it respond. Once it works locally, tag the image with your Docker Hub account and a fresh repository name, then push:

docker image build -t myaccount/testnode .
docker container run --rm -p 80:3000 myaccount/testnode
docker image push myaccount/testnode
  • Verify the new repo appears on Docker Hub
  • Remove the local image: docker image rm myaccount/testnode
  • Re-run it: docker container run --rm -p 80:3000 myaccount/testnode — Docker pulls the image again from the Hub

Your Dockerfile may look different from mine — that's fine. The build must succeed without errors and the page must load in a browser on localhost. As with previous exercises, the next lesson walks through one possible solution if you get stuck.