Dockerfile

  • Dockerfiles are part process workflow and part art

Commands

  • Each of the commands mentioned below is an actual layer
  • The order of the mentioned commands is important as it works top->down

FROM

  • package managers like apt and yum are one of the reasons to build containers FROM Debian, Ubuntu, Fedora or CentOS

ENV - Environment Variables

  • One reason they were chosen as preferred way to inject key/value is they work everywhere, on every OS and config

RUN

  • Executing shell commands inside the container as it is building it

    • Install software from the package repository

    • Unziping

    • Create/Move/Delete some folders/files inside the container itself

    • Run shell scripts

    • Add additional repositories to package manager sources list

    • etc.

  • Access to all the commands and binaries that have been installed with the OS release

  • Add commands with ampersand '&&' sign to execute these commands as a one layer

    • When placing command on next line use the backslash '\'
LOGGING SETUP
  • Everything has to be sent to stdout and stderr
    • We achieve this by creating symlink from log file to device file
# Example
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
    && ln -sf /dev/stderr /var/log/nginx/error.log

EXPOSE

  • Expose ports on the docker virtual network
  • To open/forward ports to host -p or -P have to be used

CMD

  • REQUIRED
  • Final command that will be run everytime we launch new container from the image or everytime we restart/start container
  • Only one CMD is allowed
    • If there are multiple, last one wins

Usage

  • Build Image from Dockerfile in current directory
docker image build -t name .

results matching ""

    No results matching ""