Up to this point, you have been running pre-existing container images from Docker Hub, built by Toradex or other third-party. That is very good and sometimes you will choose to use container images as they are provided.
On the other hand, sometimes you will need to customize a container image with additional libraries, tools and your own application. To fulfill this goal, the Dockerfiles exist.
Copy the following content into the newly created file:
Warning: a standard Dockerfile has no extension, therefore make sure your file is not named Dockerfile.txt, especially since file extensions are hidden by default. Consult this lesson's FAQ for details about naming.
quickstart\Dockerfile
FROM --platform=linux/arm64 torizon/debian:2-bullseye
RUN apt update && apt installnano-y
Note: If you wish, modify the Dockerfile to include more commands, such as RUN apt install python.
In this example, the FROM command shows where to get the base of our Docker image. It is important to set the platform correctly, otherwise when you deploy it to the board, the container may not work or malfunction.
We also run some commands to install packages from Debian feeds, to test if the build really works.
A Dockerfile is a text file containing instructions for building a Docker image. At the Docker Documentation there is a lot of information about them, and guidelines which we will use in this article.
This is a sample Dockerfile:
Dockerfile
# Points to a base, pre-existing image. In this case, it points to the [ubuntu container](https://hub.docker.com/_/ubuntu), tagged with version 18.04;
FROM ubuntu:18.04
# Copies files from the host machine to the created image;
COPY script.sh /root
# Runs commands as root on the created image;
RUN apt update && apt install nano
# Specifies what command will run when a new container is created based on the resulting image.
CMD [ "./startup.sh" ]
Warning: Be aware that the resulting image will be compatible with the host system architecture only, by default.
Yes, you can. The command docker build accepts a parameter for specifying a Dockerfile with a name different from the standard one, which enables you to have separate Dockerfiles for development vs. production, or for different base images, for instance, Python vs. Python slim or the latest stable vs. bleeding edge release of a distro. For example for a Dockerfile named foo.Dockerfile:
$ docker build -f foo.Dockerfile .
Any name is accepted, though you may consider using a standard. For instance, some Visual Studio Code plugins automatically have syntax highlight for any files with .Dockerfile extension, such as prod.Dockerfile and dev.Dockerfile.