DOCKER - 4 9 Exercise Create a Dockerfile

Time to build your own image from a Dockerfile. A common task for a Docker admin is to "dockerize" an existing application, often without deep knowledge of the language or the packages it uses. The process: study an official image, pick the best base with FROM, and stitch in the build instructions your app needs until you have a working container.

The brief — dockerize a Node.js app

We'll start from an existing Node.js web app. You don't need to know anything about Node beyond the fact that it's a web application. Your job is to write a Dockerfile that builds it, then test it in a container, push the image to Docker Hub, delete the local copy, and finally re-run it from the registry to confirm everything still works end to end.

  • Use the official Node image on Docker Hub — its README is well documented
  • Pick the Alpine variant (much smaller than the default)
  • Pin to the Node 6.x branch (any tag under 6 works)
  • Expected result: open localhost in your browser and see the app

Once the local container runs successfully, tag the image with your Docker Hub account and a fresh repository name, then push it. After verifying it appears on Docker Hub, delete the image from your local cache so you can prove the round trip works:

docker image build -t myaccount/node-app .
docker container run -d -p 80:3000 --name web myaccount/node-app
# open localhost in browser → app should answer

docker image push myaccount/node-app
docker image rm myaccount/node-app
docker container run -d -p 80:3000 --name web2 myaccount/node-app
# Docker re-downloads from Hub, then runs the app again

Your Dockerfile may look a little different from mine — that's fine. As long as the build completes without errors and the web page answers on localhost, the exercise is a success. The next lesson walks through one possible solution.