The instruction is not case-sensitive, but the convention is to be UPPERCASE to distinguish them from arguments more easily.
add # to add a single-line comment
... 2/25
.dockerignore
Before sending the context to the Docker daemon, the Docker CLI checks if a .dockerignore file is in the root directory. If so it excludes files/dirs that match patterns in it.
It works in a similar way of the .gitignore
... 3/25
DOCKERFILE KEYWORDS:
FROM
RUN
CMD
EXPOSE
ENV
ADD
COPY
ENTRYPOINT
VOLUME
USER
ARG
ONBUILD
HEALTHCHECK
SHELL
Let's see them one by one:
... 4/25
FROM
Usually the first instruction in a Dockerfile.
Initialize s a new build stage and sets the BASE IMAGE for the subsequent instructions
One of the most common use cases is using a public image present in the Docker-Hub
... 5/25
RUN (core concept)
It executes commands in a new layer
It has 2 formats:
- RUN <command> : the command is run in a shell, which by default is /bin/sh -c on Linux or cmd /S /C on Windows)
- RUN ["executable", "param1", "param2"] (exec form)
... 6/25
CMD
It provides defaults for an executing container.
These defaults can include an executable, or they can omit the executable, specifying an ENTRYPOINT instruction.
There can only be one CMD instruction in a Dockerfile. Only the last CMD will take effect.
... 7/25
CMD has three forms:
-CMD ["executable","param1","param2"] (exec form, this is the preferred form)
-CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
-CMD command param1 param2 (shell form)
... 8/25
LABEL
It adds metadata to an image.
They are inherited If they are included in base or parent images
If a label already exists with a different value, the recent one overrides the older one
Labels can be viewed using the docker inspect <image> command
... 9/25
EXPOSE
It informs that the container will listen on the specified port at runtime. A protocol can also be specified, and the default one is TCP
For example:
EXPOSE 80/tcp
EXPOSE 80/udp
... 10/25
ENV
It sets the environment variable <KEY> to the value <VALUE>
They will be used as environment variables in the container run from the image.
They will be used for the subsequent layers aswell.
... 11/25
ADD
It copies new files/dirs/remote URLs from the source.
It adds them to the filesystem of the image
Two forms:
-ADD [--chown=<user>:<group>] <src>... <dest>
-ADD [--chown=<user>:<group>] ["<src>",... "<dest>"]
The --chown is only supported for Linux containers
... 12/25
COPY
It copies new files/dirs from <SRC> to the filesystem of the container at the <DEST> path.
Arguments to docker run <image> will be appended after all elements in an exec form ENTRYPOINT, overriding the elements specified with CMD
... 16/25
VOLUME
It creates a mount point with a name, marking it as holding externally mounted volumes from native host/other containers.
<docker run> initializes the volume with data at the location.
The <KEY> can be:
- a JSON array
- a string with multiple arguments
... 17/25
USER
It sets the user name/UID to use when running the image and for any following instruction in the
Dockerfile for:
- RUN
- CMD
- ENTRYPOINT
... 18/25
WORKDIR
It sets the working directory for any subsequent instruction:
- RUN
- ADD
- COPY
- CMD
- ENTRYPOINT
If the WORKDIR doesn’t exist, it will be created.
... 19/25
ARG
It defines a variable that users can pass at build-time using <docker build ...> by using the flag
--build-arg <VARIBLE>=<VALUE>.
If a user specifies a build argument that was not defined in the Dockerfile, the build throws a warning.
... 20/25
ARG and ENV instructions:
ARG and ENV instruction specify variables available to the RUN instruction.
ENV instruction overrides an ARG instruction of the same name.
... 21/25
ONBUILD
It adds to the image a trigger instruction to be executed when the image is used as the base for another build.
This is useful for images built as a base to other images
The trigger will be executed in the context of the downstream build
... 22/25
STOPSIGNAL
It sets the system call signal sent to the container to exit.
This signal can be:
- a valid unsigned number matched in the kernel’s syscall table
- a signal name in the format SIGNAME, (eg: SIGKILL).
... 23/25
HEALTHCHECK
It’s used to check if a container is working properly.
This can detect cases such as a web server that is stuck in an infinite loop and unable to handle new connections, even though the server process is still running.
... 24/25
SHELL
It allows the override the default shell for the command in the Dockerfile
The default shell are:
- Linux => ["/bin/sh", "-c"]
- Windows => ["cmd", "/S", "/C"].
SHELL instruction can be used on Linux for zsh, csh, tcsh, ...
... 25/25
• • •
Missing some Tweet in this thread? You can try to
force a refresh
The Docker client talks to the Docker daemon (server), which menages different docker objects:
- Images
- Containers
- Networks
- Volumes
Let's see in details:
... 1/12
The Docker client and the daemon can run on the same system, or they can be connected remotely using HTTP protocol.
The connection is established using REST APIs, over UNIX sockets/network interface
... 2/12
DOCKER DAEMON (SERVER)
The Docker daemon (dockerd) is a process, which runs in the background, that manages the docker objects (images, containers, networks, volumes). It processes Docker API requests
I will definitely use it for the next projects that will include a frontend.
A Thread of my impressions 🧵
✅SIMPLE = GOOD
The first thing that struck me was the simplicity with which it can be integrated into a simple project.
It is from this that we know if a Framework will be successful and I'm sure it will.
I don't know why something like this hasn't existed for a long time
🛠️CUSTOMIZATION
I was expecting something like bootstrap but improved instead the approach is completely different.
Yes in Bootstrap you can always customize the elements, but I always found it complicated and every time I found myself rewriting the same custom classes.