DOCKERFILE:

What is it?
A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.

In other words, a Dockerfile allows you to avoid writing each command one by one in a super simple way

... 1/25
FORMAT:

The format of a Dockerfile is simple:

# Comment
INSTRUCTION args
INSTRUCTION args
INSTRUCTION args

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.

Two forms:

COPY [--chown=<user>:<group>] <src>... <dest>
COPY [--chown=<user>:<group>] ["<src>",... "<dest>"]

The --chown is only supported for Linux containers

... 13/25
ADD or COPY ?

If you’re copying in local files to your Docker image, always use COPY because it’s more explicit.

... 14/25
ENTRYPOINT

It allows you to configure a container that will be run as an executable.

It has two forms:

EXEC FORM: ENTRYPOINT ["executable", "param1", "param2"]

SHELL FORM: ENTRYPOINT command param1 param2

... 15/25
ENTRYPOINT and CMD arguments

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
 

Keep Current with Francesco Ciulla

Francesco Ciulla Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @FrancescoCiull4

27 Apr
What is a Docker container?

The easiest way to understand what a container is is to think of it as a process that runs on our machine, isolated from other processes.

To make this happen, Linux namespaces and cgroups are used under the hood.

... 1/4
A container has its own dedicated filesystem, provided by an image.

The image contains:

-dependencies
-configuration
-binaries
-environment variables
-other important data related to the container to be instantiated.

Many containers can be run from a single image

... 2/4
Technically, a container is first created, then, started.

To do this with a single command, we can use the 'docker run' command.

to see all the containers running on the host:
'docker container ls -a'

or just
'docker ps -a'

... 3/4
Read 4 tweets
23 Apr
Docker Architecture

Docker uses a client-server architecture.

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

... 3/12
Read 12 tweets
15 Apr
🟢That was a V-BLAST!!!🟢

I Tried VueJs for the First Time, it really impressed me!

My regret: We just scratched the surface

Thank you @themarcba for guiding me! I hope to give back if you wanna try🐳!

Special Thanks to @spences10 for the Donation!

🧵Of Best Moments Below.
Time: 4:50

Marc Experience as a Speaker and Tech Stack

Time 6:54

I will his next Guest in Decoding the Code Series!

Read 13 tweets
18 Feb
Today I tried Flutter and Dart for the first time, live, together with @tadaspetra

Here there are some highlights!!!

Spoiler:

In 100 minutes, from ZERO, we got a working built application (apk file) for Android, starting from zero.

On Windows.

That's amazing

A 🧵
Video Link:


Would you like a shorter version of this live?
Please let me know!
These were the Livestream Goals and what I had already installed

I had already:
- VS code installed
- Android Studio (wrong SDK version)
- Emulator Set

Goals:
- Install dart language
- Install Flutter
-Create a hello-world app
- Modify it a little bit
- Create the apk file
Read 21 tweets
7 Jan
Tailwind CSS - First impressions

I have Tried Tailwind CSS for the first time.

I studied directly from the official docs

I can say that I like what I've seen so far.

I will definitely use it for the next projects that will include a frontend.

A Thread of my impressions 🧵 Image
✅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.
Read 7 tweets
5 Jan
Yesterday I stayed away from social networks to think about 2021 without distractions.

I'll divide my week with "MAIN TOPIC OF THE DAY".

This is good for me, and for those who follow me to get free updates.

Thread below. Ask me Anything

RT if this can be useful to a friend. Image
⚛️MONDAY: REACT

I'll dedicate Mondays to React.

I will start with some small tips on Twitter, then with some basic projects.

It will be funny!
🟩🟨TUESDAY: NODE & JAVASCRIPT

I'll dedicate Tuesdays to Node JS

I will share some info about it and Javascript of course:

Tweets, some small projects.

I will show every project and library/feature I'll use.
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!