Search by Tags

Writing Your First Dockerfile

 

Your progress

 

Overview

Up to this point, you have been running pre-existing images from Docker Hub, built by Toradex or other third-party. But it is possible to create your own Docker image to load whatever application you wish. 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 Windows 10 Pro / Enterprise / Education.
  • Successfully completed the previous lesson from this guide.

For this lesson:

  • Docker for Windows downloaded and running.

Step 1

In your Windows 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:

Note: 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/debian-lxde:buster RUN apt update && apt install nano -y CMD [ "startx" ]

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

Step 2

Open Powershell, login to Docker CLI:

docker login

Follow the prompt with your Docker Hub credentials.

Step 3

Enter your getting-started folder and build the image:

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

Step 4

Upload the image to your Docker Hub:

docker push <your-username>/gs-torizon

FAQ

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