CIS 527



Lab 5.A - Building Images

Building Images

  • Create Dockerfile
  • Choose base image
  • Configure image
  • Copy application files
  • Configure application
  • Set command and ports

Follow Along!

https://docs.docker.com/get-started/

Step 1 - Get Code

git clone https://github.com/docker/getting-started.git
cd getting-started/app
# open in text editor

Step 2 - Create Dockerfile

# syntax=docker/dockerfile:1
FROM node:12-alpine
RUN apk add --no-cache python2 g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
EXPOSE 3000

Step 3 - Build & Run

docker build -t getting-started .
docker run -d -p 3000:3000 getting-started

Step 4 - Updated & Rebuild

# edit src/static/js/app.js line 56
docker build -t getting-started .
docker stop [container]
docker run -d -p 3000:3000 getting-started

Step 5 - Share Container!

  • Docker Hub
  • GitHub
  • GitLab

Step 6 - Scan Image

docker scan getting-started

Step 7 - Cached Layers

# syntax=docker/dockerfile:1
FROM node:12-alpine
RUN apk add --no-cache python2 g++ make
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --production
COPY . .
CMD ["node", "src/index.js"]
EXPOSE 3000
# .dockerignore
node_modules