Search by Tags

Writing Your First Dockerfile - ARM64

 

Your progress

 

Overview

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.

In this section, you will:

  • Write a Dockerfile.
  • Build a Docker image from the Dockerfile.
  • Upload the image to Docker Hub.
Typographic Conventions

Prerequisites

For this Quickstart Guide:

  • Development computer with Windows 10 version 2004 (a.k.a. May 2020 update) or higher.
  • Successfully completed the previous lesson from this guide.

For this lesson:

  • Docker downloaded and running. If you are not sure, please refer to the previous lessons.

Note: Carefully read this module's cover page clicking on "Module 3: Creating my Own Container" on the left menu bar before starting this lesson.

Step 1

In your development PC, create a new folder named Getting Started on the Desktop

Step 2

To create a Dockerfile, open a text editor of your choice. We'll use the NotePad++:


  • Notepad++

    Notepad++

Step 3

Copy the following content into the NotePad++ editor:

getting-started\Dockerfile
FROM --platform=linux/arm64 torizon/debian:2-bullseye
 
RUN apt update && apt install nano -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.

Step 4

After copying the content, we need to save it in our Getting Started folder. Click on the button referred on the image below:


  • Saving the Dockerfile

    Saving the Dockerfile

Make sure to type "Dockerfile" inside double quotes on the file name, this will guarantee it to have no extension.


  • Save the file on the Getting Started folder

    Save the file on the Getting Started folder

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 on Windows. Consult this lesson's FAQ for details about naming.

Step 5

Inside the Getting Started folder, hold the left shift key of your keyboard and click on the "Open PowerShell window here" option


  • Open PowerShell window

    Open PowerShell window

From the PowerShell tab you just opened, log in to the Docker CLI:

Note: Remember to keep the Docker Desktop application opened before running these commands

$ docker login

  • Docker login

    Docker login

Follow the prompt with your Docker Hub credentials. Visit Docker Hub page to create a Docker ID if you don't have credentials.

Step 6

Now you can build the image:

$ docker build --pull -t <username>/gs-torizon .

Note that this <username> is your Docker Hub username.

Step 7

Upload the image to your Docker Hub:

$ docker push <username>/gs-torizon

Now your custom container image is accessible from Docker Hub just like the other images you've used until this lesson.

FAQ

What is a Dockerfile?
What does the created Dockerfile do?
Can I have multiple Dockerfiles with different names?