Dockerfile - kimschles/schlesinger-knowledge GitHub Wiki

Directives

Dockerfile Gotchas

FROM

  • Sets the base image for the rest of the Dockerfile instructions
  • Sets up the envioronment: node.js, ruby, java, etc.

COPY

ADD

ADD say_hello.sh /

  • Makes a copy of the file you're specifiying in the root director of the filesystem

COPY vs. ADD *

CMD

  • CMD allows you to treat your docker container like an executable binary
  • If you only use

ENTRYPOINT

CMD vs. ENTRYPOINT

  • You can manually override CMD with docker run
  • Entrypoint will overrider commands with docker run

RUN

  • create a new container, start it and run a process in it
  • this command will run the commands in a new layer on top of the current image and commit the results

EXEC

  • when you want to run a command in an existing container

RUN vs EXEC

EXPOSE

  • The port on which the container listens for connetions
  • Apache Web Server: EXPOSE 80
  • MongoDB: EXPOSE 27017

IP Address is like an address A port is like a mailbox in an apartment building

Like a telephone switchboard. A port is like the jack.

ARG

  • Allows the developer to set values during the docker build process

HEALTHCHECK

  • A way to check if a running container is healthy
⚠️ **GitHub.com Fallback** ⚠️