Build Own Image

Assignment

  • Take existing Node.js app and Dockerize it
  • Make Dockerfile. Build it. Test it. Push it. (rm it). Run it.
  • Expect this to be iterative. Rarely it is right the first time.
  • Details in dockerfile-assignment-1/Dockerfile
  • Use the Alpine version of the official 'node' 6.x image
  • Expected result is web site at http://localhost
  • Tag and push to your Docker Hub account (free)
  • Remove your image from local cache, run again from Hub

Solution

Dockerfile

FROM node:6-alpine

EXPOSE 3000

RUN apk add --update tini\
    && mkdir -p /usr/src/app

WORKDIR /usr/src/app

COPY package.json package.json

RUN npm install\
    && npm cache clean --force

COPY . ./

CMD ["tini", "--", "node", "./bin/www"]

Series of commands I had to run to finish this assignment after I done Dockerfile

# build image from dockerfile
docker build -t node-app .
# run container
docker container run -p 80:3000 --rm node-app   # app is working in browser
# remove container
docker container rm -f node-app     # on windows automatic --rm sometimes fail
# re-tag container for publish
docker image tag node-app stefanjarina/node:6-alpine
# publish to DockerHub
docker push stefanjarina/node:6-alpine
# remove cached version
docker image rm node-app stefanjarina/node:6-alpine
# download and run image from DockerHub
docker container run -p 80:3000 --rm stefanjarina/node:6-alpine

results matching ""

    No results matching ""