More Docker file - Dan Wahlin

      1. (simply docker image building instructions)
      2. Can name this file anything you want. Convention is simply ‘Dockerfile or, if multiple docker files, use .dockerfile as extension (ie, ‘node.dockerfile’)
      3. Simply a text file with instructions to build an image
      4. Common Dockerfile commands
        1. “FROM” - base image (ie, node) to start from
        2. “MAINTAINER” - who maintains the image (you)
        3. “RUN” - define actions that are done as image is created. (ie, npm install)
          1. (grab file from internet, npm start, etc). Typically to install pkgs
          2. Each RUN commands creates a new image layer
        1. “COPY” - move files into container (ie, source code. “Baked” into image).
        2. “ENTRYPOINT” - command that gets exec when container is spun up
          1. (ie, ‘npm start’). Makes container an executable -like an .exe file
          2. ENTRYPOINT and CMD are different but interchangeable

Over-ride default CMD by specifying an argument after the image name when starting the container:

ENTRYPOINT can be similarly overridden but it requires the use of the --entrypoint flag

        1. “WORKDIR” - defines work dir. Location that commands will run from (ie, npm install, npm start). RUN, ENTRYPOINT, CMD, ADD & Copy
        2. “EXPOSE” - ie, expose a port
        3. “ENV” - set environment variables
        4. “VOLUME - define volume for container -see volume discussion above

Dockerfile example

      1. FROM node:latest → gives latest version of node image
      2. FROM node:5.5.0 → gives you the specified version (5.5.0)
      3. ENV NODE_ENV=production
      4. ENV PORT=3000 → note no spaces between =

(or )

ENV NODE_ENV=production PORT=3000

      1. MAINTAINER Doug W → just metadata (information others might want to know)
      2. COPY . /var/www → copy entire cur dir (.) into container folder /var/www

(“bakes” a file layer into the image Docker builds up). Will NOT live update

      1. WORKDIR /var/www → sets work dir (where commands RUN ie, ‘npm install’)
      2. Volume [“/var/www”, “/logs”] → Docker set sources on localhost. This way logs stick around on local host even if container is deleted (unless use rm -v)
        1. CHALLENGE: Volume lives outside of the container. Therefore when image is built, the volume does not yet exist. Docker creates the Volume when CONTAINER is made (not when image is made). When container is made (and Volume is set up), Dockerfile’s “Run npm install” command has already ran. The files are in /var/www BUT Dockerfile’s Volume command kind of wipes out those files (node_modules). Therefore /var/www no longer has node_module files to share with host. Solution, delete Volume command from Dockerbuild. Can do this because we don’t need to persist anything in this example (no need for Volume).
      3. RUN npm install
      4. EXPOSE 3000 → intern cont port ‘exposed’ (can still assign via $ docker run)

-or- EXPOSE $PORT → since port is defined as environmental variable

        1. Note: did not NEED to expose port since Express setup did (3000)
      • ENTRYPOINT [“npm”, “start”] → JSON array. Need double quotes(or ENTRYPOINT npm start → works but best practice is JSON array- above

results matching ""

    No results matching ""