Skip to content

Latest commit

 

History

History
61 lines (48 loc) · 2.91 KB

6-dockerfile.md

File metadata and controls

61 lines (48 loc) · 2.91 KB

Dockerfile Basics

Instructions

  • .dockerignore
  • FROM - Sets the Base Image for subsequent instructions
  • MAINTAINER - Set the Author field of the generated images
  • RUN - Execute any commands in a new layer on top of the current image and commit the results
  • CMD - Provide defaults for an executing container
  • EXPOSE - Informs Docker that the container listens on the specified network ports at runtime. NOTE: does not actually make ports accessible
  • ENV - Sets environment variable
  • ADD - Copies new files, directories or remote file to container. Invalidates caches. Avoid ADD and use COPY instead
  • COPY - Copies new files or directories to container
  • ENTRYPOINT - Configures a container that will run as an executable
  • VOLUME - Creates a mount point for externally mounted volumes or other containers
  • USER - Sets the user name for following RUN / CMD / ENTRYPOINT commands
  • WORKDIR - Sets the working directory.
  • ARG - Defines a build-time variable.
  • ONBUILD - Adds a trigger instruction when the image is used as the base for another build
  • STOPSIGNAL - Sets the system call signal that will be sent to the container to exit
  • LABEL - Apply key/value metadata to your images, containers, or daemons
  • HEALTHCHECK - Instruction tells Docker how to test a container to check that it is still working.

Basic

FROM node:8.12.0-alpine
ENV SERVICE_PORT=80
ENV NODE_ENV=production
EXPOSE 80

ADD . /app
WORKDIR /app
CMD npm install

ENTRYPOINT node server

Advanced

FROM node:8.12.0-alpine

STOPSIGNAL SIGINT
ENV SERVICE_PORT=8080
EXPOSE 8080
LABEL name "nodejs-app"

RUN apk add --no-cache dumb-init

HEALTHCHECK --interval=1m --timeout=3s \
  CMD curl -f http://localhost:8080/ || exit 1

RUN mkdir /app
WORKDIR /app
COPY package.json /app
RUN npm install --production
COPY . /app

ENTRYPOINT dumb-init npm start