Search by Tags

Writing Your First Dockerfile

 

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 Getting Started Guide:

  • Development computer with Ubuntu 18.04 LTS.
    • Commands and instructions may vary slightly on other Ubuntu releases and Linux distributions.
  • Successfully completed the previous lessons 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 Linux machine, create a new folder named getting-started on the Desktop and a new file named Dockerfile inside it. 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.

getting-started\Dockerfile
FROM torizon/arm32v7-debian-base RUN apt update && apt install nano -y

Note: If you wish, modify the Dockerfile to include more commands, such as RUN apt install python.

Step 2

From the command-line, in your development PC, login to Docker CLI:

$ docker login

Follow the prompt with your Docker Hub credentials.

Step 3

Enter the previously created getting-started folder and build the image:

$ cd ~/getting-started
$ docker build -t <username>/gs-torizon .

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

Step 4

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?