Dockerfile
Dockerfile Instructions
ENTRYPOINT vs CMD
ENTRYPOINT
It sets the main command to be executed when running the container.
You cannot override ENTRYPOINT without --entrypoint flag.
CMD
It provides default arguments for the ENTRYPOINT or the command to run if no ENTRYPOINT is specified.
You can override CMD by providing command line arguments when running the container e.g.:
ENTRYPOINT + CMD
Putting them together allows you to set a fixed command with default parameters that can be overridden.
docker run my_image # will run `python app.py`
docker run my_image other.py # will run `python other.py`
ARG vs ENV
ARG
Variables for build-time (only available during build time).
ENV
Environment variables for runtime (available when container is running).
These environment variables are available during build time and runtime.
From
It specifies the base image for the Dockerfile.
RUN
Execute commands in a new layer and commit the results.
LABELS
Adds metadata to an image.
MAINTAINER
Author of the image.
COPY
Adds files and folders into image.
ADD
Download from a link and put in the image (it can even archive and unarchive).
VOLUME
Creates a mount point and mark it as external mount volume.
EXPOSE
Active network ports at container runtime (not buildtime).
USER
Sets the user name (or UID).
WORKDIR
Set shell spawn location in directory.
ONBUILD
Adds to the image a trigger instruction to be executed at a later time.
SHELL
Set the default shell of an image e.g.: bash or sh.
STOPSIGNAL
Defines which signal Docker sends to PID 1 in the container when stopping it.
HEALTHCHECK
Tells Docker how to check if a container is still working correctly (healthy).
Syntax:
Create Dockerfile
FROM jenkins/jenkins:2.506-slim-jdk17 # use official Jenkins image as base
USER root
RUN apt-get update && apt-get install -y \ # install dependencies
git \
maven
USER jenkins
RUN jenkins-plugin-cli --plugins \
"warnings-ng" \
"sonar"