# Docker tutorial for beginners

In our Docker tutorial, we introduce you to the [Docker](https://www.ionos.ca/digitalguide/server/know-how/what-is-docker/) virtualization platform and show you how to use Docker on your [Ubuntu](https://www.ionos.ca/digitalguide/server/know-how/ubuntu-the-linux-system-for-everyone/) 22.04 system using easy-to-follow instructions.

## Structure and features of Docker

“Build, Ship, and Run Any App, Anywhere” — this is Docker’s motto. The open-source container platform offers a flexible, low-resource alternative for the emulation of hardware components based on virtual machines (VMs).

While **traditional hardware virtualization** is based on launching multiple guest systems on a common host system, Docker applications are run as isolated processes on the same system with the help of **containers**. This is called [**container-based virtualization**](https://www.ionos.ca/digitalguide/server/know-how/server-containers-virtualisation-without-emulation/), also referred to as **operating-system-level virtualization**.

[![Image: Virtual machines and software containers in comparison](https://www.ionos.ca/digitalguide/fileadmin/_processed_/f/9/csm_virtual-machines-compared-to-docker-containers_1216df397f.webp "Virtual machines and software containers in comparison")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Schaubilder/virtual-machines-compared-to-docker-containers.png) While each virtual machine launches its own operating system, Docker containers share the core of the host system One big advantage of container-based virtualization is that applications with different requirements can run in isolation from one another without requiring the overhead of a separate guest system. Additionally, with containers, applications can be deployed **across platforms and in different infrastructures** without having to adapt to the hardware or software configurations of the host system.

Docker is the most popular software project that provides users with **container-based virtualization technology**. The open-source platform is based on three basic components. In order to execute containers, users only need the **Docker engine** as well as special **Docker images**, which can be obtained via the **Docker hub** or created themselves.

Tip Docker containers and images are mostly generic, but can be highly customized as needed. You can read more about it in our article on [Docker containers](https://www.ionos.ca/digitalguide/server/know-how/docker-container/).

### Docker images

Similar to virtual machines, Docker containers are based on [Docker images](https://www.ionos.ca/digitalguide/server/know-how/docker-images/). An image is a read-only template that contains all instructions that the Docker engine needs to create a container. A Docker image is described as a **portable image of a container** in the form of a text file, also called a [Dockerfile](https://www.ionos.ca/digitalguide/server/know-how/dockerfile/). If a container is to be launched on a system, then first a package with the respective image is loaded, as long as it doesn’t exist locally. The loaded image provides the necessary **file system including all parameters** for the runtime. A container can be viewed as a running process of an image.

### The Docker hub

The Docker hub is a cloud-based **registry for software repositories**, a type of library for Docker images. The online service is split between a public and a private section. The public section offers users the option to upload their own developed images and share with the community. Here, there are a number of official images available from the Docker developer team and established open-source projects. Images uploaded to the private section of the registry aren’t accessible publicly and so can be shared, for example, within a company’s internal circle or with friends or acquaintances. The Docker hub can be accessed on [*hub.docker.com*](https://hub.docker.com/ "Docker Hub website").

### The Docker engine

At the heart of the Docker project is the Docker engine. This is an **open-source client server application**, which is available to all users in the current version on all established platforms.

The basic architecture of the Docker engine is divided between three components: A **daemon** with server functions, a **programming interface (API)** based on the programming paradigm REST (Representational State Transfer), and the **operating system terminal** (command line interface, CLI) as a user interface (client).

- **Docker daemon**: As a server for the Docker engine, a daemon process is used. The Docker daemon runs in the background of the host system, and is used for the central control of the Docker engine. This function creates and manages all images, containers, or networks.
- **REST-API**: The REST-API specifies a set of interfaces that allow other programs to communicate with the Docker daemon and give it instructions. One of these programs is the terminal of the operating system.
- **Terminal**: As a client program, Docker uses the operating system’s terminal. This, integrated with the Docker daemon via the REST-API, enables users to control it through scripts or user input.

Tip In 2017, the Docker engine was renamed to *Docker Community Edition* (abbreviated to Docker CE), but the official documentation and Docker repositories mostly still use the old name. In addition to Docker CE, there is also *Docker Enterprise Edition* (Docker EE), which has some premium features. However, it is not free and is more suitable for enterprises.

With [Docker commands](https://www.ionos.ca/digitalguide/server/know-how/docker-commands/), user software containers can be started, stopped, and managed directly from the terminal. The Daemon is addressed via the command `docker` and instructions like `build`, `pull`, or `run`. Client and server can be on the same system. Users are also given the option to access a Docker daemon on another system. Depending on the type of connection being established, communication between the client and the server takes place via the REST-API, via UNIX sockets, or via a network interface.

The following graphic illustrates the **interplay of the individual Docker components** with the example commands `docker build`, `docker pull`, and `docker run`:

[![Image: Schematic representation of the Docker architecture](https://www.ionos.ca/digitalguide/fileadmin/_processed_/e/1/csm_docker-architecture-schematic_0cb6890f75.webp "Schematic representation of the Docker architecture")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Schaubilder/docker-architecture-schematic.png) The Docker architecture is based on the cooperation of the client (terminal The command `docker build` instructs the Docker daemon to create an image (dotted line). For this, a corresponding **Dockerfile** needs to be available. If the image isn’t to be created, but instead loaded from a repository in the Docker hub, then the `docker pull` command is used (dashed line). If the Docker daemon is instructed via `docker run` to launch a container, the background program checks whether or not the corresponding container image is locally available. If it is, then the container is run (solid line). If the daemon can’t find the image, it automatically initiates a pull from the repository.

## Working with Docker

Now it’s time to get familiar with the **container platform applications**. If you have not yet installed the Docker engine, you can do so via the Linux Terminal. You can find instructions on how to do this in our article entitled “[Install Docker on Ubuntu 22.04](https://www.ionos.ca/digitalguide/server/configuration/install-docker-on-ubuntu-2204/)”. Learn below how to control the Docker Engine from the terminal, what the Docker Hub can do for you, and why Docker containers could revolutionize the way you work with applications.

Tip If you want to install Docker on another Linux distribution or Windows, the following instructions will help:

- [Install Docker on Debian 11](https://www.ionos.ca/digitalguide/server/configuration/install-docker-on-debian-11/)
- [Install Docker on Ubuntu 20.04](https://www.ionos.ca/digitalguide/server/configuration/install-docker-on-ubuntu-2004/)
- Install Docker on CentOS 7
- [Install Docker on Windows 10](https://www.ionos.ca/digitalguide/server/configuration/docker-on-windows-10/)
- [Install Docker on Windows 11](https://www.ionos.ca/digitalguide/server/configuration/docker-windows-11/)
- [Install Docker on Raspberry Pi](https://www.ionos.ca/digitalguide/server/configuration/docker-on-raspberry-pi/)

### How to control the Docker engine

Since version 16.04, Ubuntu has used the **background program *systemd***(short for “system daemon”) to manage processes.*Systemd*is an init process, also used on other Linux distributions like RHEL, CentOS, or Fedora. Typically,*system*receives the process ID 1. As the first process of the system, the daemon is responsible for starting, monitoring, and ending all following processes. For previous Ubuntu versions (14.10 and older), the background program*upstart* takes over this function.

The Docker daemon can also be controlled via *systemd*. In the standard installation, the container platform is configured so that the Daemon automatically starts when the system is booted up. This default setting can be customized via the command line tool **systemctl**.

With *systemctl*, you send commands to *systemd* to control a process or request its status. The syntax of such a command is as follows:

```bash
systemctl [OPTION] [COMMAND]
```

Some commands refer to specific resources (for example, Docker). In the terminology of *systemd*, these are referred to as units. In this case, the command results from the respective instruction and the name of the unit to be addressed.

If you would like to activate the **autostart of the Docker daemon** (*enable*) or deactivate it (*disable*), use the command line tool *systemctl* with the following commands:

```bash
sudo systemctl enable docker
sudo systemctl disable docker
```

The command line tool *systemctl* allows you to query the **status of a unit**:

```bash
sudo systemctl status docker
```

If the Docker engine on your Ubuntu system is active, then the output in the terminal should look like the following screenshot:

[![Image: The status query via systemctl shows: The Docker engine is active (running)](https://www.ionos.ca/digitalguide/fileadmin/_processed_/f/7/csm_docker-status-active-running_f52601bd11.webp "The status query via systemctl shows: The Docker engine is active (running)")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-status-active-running.png) Status query via systemctl: The Docker Engine is active (running) If your Docker engine is currently deactivated, then you’ll receive the status declaration *inactive (dead)*. In this case, you need to manually launch the Docker daemon to run containers.

[![Image: The status query via systemctl* shows: The Docker engine is inactive (dead)](https://www.ionos.ca/digitalguide/fileadmin/_processed_/d/a/csm_docker-status-inactive_cad5668ee9.webp "The status query via systemctl* shows: The Docker engine is inactive (dead)")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-status-inactive.png) Status query via systemctl: The Docker engine is inactive (dead) If you would like to **manually start, stop, or restart your Docker engine**, address *systemd* with one of the following commands.

To **start the deactivated daemon**, use *systemctl* in combination with the command `start`:

```bash
sudo systemctl start docker
```

If the **Docker daemon is to be ended**, use the command `stop` instead:

```bash
sudo systemctl stop docker
```

A **restart of the engine** is prompted with the command `restart`:

```bash
sudo systemctl restart docker
```

### How to use the Docker hub

If the Docker engine represents the heart of the container platform, then the Docker hub is the soul of the open-source project. This is where the community meets. In the **cloud-based registry**, users can find everything that they need to breathe life into their Docker installation.

The online service offers **diverse official repositories with more than 100,000 free apps**. Users have the option to create an image archive and use them collectively with work groups. In addition to the professional support offered by the development team, beginners can find connections to the user community here. A forum for community support is available on [**GitHub**](https://github.com/docker/hub-feedback/issues "Docker’s GitHub website").

[![Image: The Docker hub: Registration](https://www.ionos.ca/digitalguide/fileadmin/_processed_/a/0/csm_docker-hub-login-page_d232488fe7.webp "The Docker hub: Registration")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-hub-login-page.png) Create your personal Docker ID for free by registering / Source: hub.docker.com #### Registering in the Docker hub

**Registering in the Docker hub is free**. Users just need an email address and their chosen Docker ID. This serves as a personal **repository namespace** later and grants users access to all Docker services. Currently, this offer includes the Docker cloud, Docker store, and selected beta programs in addition to the Docker hub. It also allows the **Docker ID** to be used as a log-in for the Docker support center as well as the Docker success portal and [Docker forum](https://www.docker.com/docker-community "Docker Community forum").

The registration process is comprised of five steps:

1. **Choose your Docker ID**: As the first part of the application, choose a username that will later be used as your personal Docker ID.
2. **Enter an email address**: Enter your current email address. Note that you will have to confirm your registration with Docker hub via email.
3. **Choose a password**: Choose a secret password.
4. **Submit your registration**: Click on “Sign up” to submit your registration. Once the data has been fully transmitted, Docker will send a link for you to verify your email address to your specified inbox.
5. **Confirm your email address**: Confirm your email address by clicking on the verification link.

The online services of the Docker project are immediately available following your registration in the browser. Here you can create repositories and workgroups, or search the Docker hub for public resources using “Explore”.

[![Image: Dashboard of the Docker hub](https://www.ionos.ca/digitalguide/fileadmin/_processed_/f/a/csm_docker-hub-dashboard_1d08a8d15d.webp "Dashboard of the Docker hub")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-hub-dashboard.png) Select and set repositories and workgroups via the Docker hub dashboard / Source: hub.docker.com You can also register directly on your operating system’s terminal via *docker login*. A detailed description of the command can be found in the [Docker documentation](https://docs.docker.com/engine/reference/commandline/login/ "Docker documentation").

In principle, Docker hub is also available to those **without an account or Docker ID**. In this case, though, only images from public repositories can be loaded. An upload (*push*) of your own images isn’t possible without a Docker ID.

#### Create repositories in the Docker hub

The **free Docker hub account** contains one private repository, and offers the possibility to create any number of public repositories. If you should need more private repositories, you can unlock these with a **paid upgrade**.

To create a repository, proceed as follows:

1. **Choose a namespace**: Newly created repositories are automatically assigned to the namespace of your Docker ID. You also have the option to enter the ID of an organization that you belong to.
2. **Label the repository**: Enter a name for the newly created repository.
3. **Add a description**: Add a short description for your repository.
4. **Set visibility**: Decide whether the repository should be publicly visible (*public*) or only accessible by you or your organization (*private*).

Confirm your entries by clicking “Create”.

[![Image: The Docker hub: Input screen for creating a repository](https://www.ionos.ca/digitalguide/fileadmin/_processed_/a/d/csm_docker-hub-repository-creation_ac7984ce9d.webp "The Docker hub: Input screen for creating a repository")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-hub-repository-creation.png) Your repositories are automatically created in the namespace of your Docker ID / Source: hub.docker.com #### Create teams and organizations

With the hub, Docker provides a cloud-based platform on which **self-created images are centrally managed** and conveniently **shared with workgroups**. In the Docker terminology, these are called organizations. Just like user accounts, organizations receive individual IDs via which images can be provided and downloaded. Rights and roles within an organization can be assigned via teams. For example, users assigned to the “Owners” team have the authority to create private or public repositories and assign access rights.

Workgroups can also be created and managed directly via the dashboard. Further information about organizations and teams can be found in the [Docker documentation](https://docs.docker.com/docker-hub/orgs/ "Workgroups - Docker documentation").

### Working with images and containers

As the first point of contact for official Docker resources, the Docker hub is our starting point for this **introduction to handling images and containers**. The developer team has provided the demo image *whalesay*, which will serve as the basis for the following Docker tutorial.

#### Download Docker images

The *whalesay* image can be found when you visit the Docker hub website and enter the term *whalesay* in the search bar next to the Docker logo.

[![Image: The search function in Docker hub](https://www.ionos.ca/digitalguide/fileadmin/_processed_/c/c/csm_docker-hub-whalesay-repos_eae5c60dab.webp "The search function in Docker hub")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-hub-whalesay-repos.png) Search the Docker hub using the search bar or the “Explore” button / Source: hub.docker.com In the search results, click on the resource with the title *docker/whalesay* to access the public repository for this image.

Docker repositories are always built according to the same pattern. In the header of the page, users find the title of the image, the category of the repository, and the time of the last upload (*last pushed*).

[![Image: Web view of a Docker repository](https://www.ionos.ca/digitalguide/fileadmin/_processed_/3/e/csm_docker-hub-official-whalesay-repo_2355257104.webp "Web view of a Docker repository")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-hub-official-whalesay-repo.png) In the repository, users generally find all information that is needed to use an image / Source: hub.docker.com Each Docker repository also offers the following info boxes:

1. **Description**: Detailed description, usually including directions for use
2. **Docker pull command**: Command line directive used to download the image from the repository (`pull`)
3. **Owner**: Information about the creator of the repository
4. **Comments**: Comment section at the end of the page

The information boxes of the repository show that *whalesay* is a modification of the open-source Perl script ***cowsay***. The program, developed by Tony Monroe in 1999, generates an ASCII graphic in the form of a cow, which appears along with a message in the user’s terminal.

To download *docker/whalesay*, use the command `docker pull`:

```bash
docker pull [OPTIONS] NAME [:TAG|@DIGEST]
```

The command `docker pull` instructs the daemon to load an image from the repository. You specify which image this is by entering the image title (*NAME*). You can also instruct Docker on how the desired command should be carried out (*OPTIONS*). Optional input includes **tags** (*:TAG*) and individual **identification numbers** (*@DIGEST*), which allow you to download a specific version of an image.

A local copy of the *docker/whalesay* image is obtained with the following command:

```bash
docker pull docker/whalesay
```

In general, you can skip this step. If you’d like to launch a container, the Docker daemon automatically downloads the images from the repository that it can’t find on the local system.

#### Launch Docker images as containers

To start a Docker image, use the command `docker run` according to the following:

```bash
docker run [OPTIONS] IMAGE [:TAG|@DIGEST] [CMD] [ARG...]
```

The only obligatory part of the `docker run` command is the name of the desired Docker image. But when you launch a container, you also have the chance to define extra options, TAGs, and DIGESTs. In addition, the `docker run` command can be combined with other commands that are run as soon as the container starts. In this case, the **CMD** (COMMAND, defined by the image creator and executed automatically when the container is started) is overwritten. Other optional configurations can be defined through **additional arguments** (*ARG…*). This makes it possible, for example, to add users or to transfer environment variables.

Use the command line directive

```bash
docker run docker/whalesay cowsay boo
```

to download the existing Perl script as an image and run in a container. You’ll see that *whalesay* differs significantly from the source script.

[![Image: Terminal output of the container docker/whalesay: The whale says “boo”](https://www.ionos.ca/digitalguide/fileadmin/_processed_/e/4/csm_docker-run-whalesay-boo-english_82f28f20b7.webp "Terminal output of the container docker/whalesay: The whale says “boo”")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-run-whalesay-boo-english.png) If docker/whalesay is run with the standard command, the Docker whale is limited to a short “boo” If the image *docker/whalesay* is run, the script outputs an ASCII graphic in the form of a whale as well as the text message “boo”, passed with the *cowsay* command in the terminal.

As with the test run, the daemon first looks for the desired image in the local file directory. Since there is no package of the same name, a pull from the Docker repository is initiated. Then the daemon starts the modified *cowsay* program. If this has run through, then the **container is ended automatically**.

Like *cowsay*, Docker’s *whalesay* also offers the option to intervene in the program sequence to influence the text output in the terminal. Test this function by replacing the “boo” in the output command with any string or with a lame whale joke, for example.

```bash
sudo docker run docker/whalesay cowsay What did the shark say to the whale? What are you blubbering about?
```

[![Image: Terminal output of the container docker/whalesay: A whale with an individual message](https://www.ionos.ca/digitalguide/fileadmin/_processed_/8/6/csm_docker-run-whalesay-joke_6337d3f36a.webp "Terminal output of the container docker/whalesay: A whale with an individual message")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-run-whalesay-joke.png) Make your Docker whale say whatever you want by placing words in his speech bubble #### Display all Docker images on the local system

If you aren’t sure whether you’ve already downloaded a particular image, you can access an **overview of all the images on your local system**. Use the following command line directive:

```bash
sudo docker image
```

The command `docker images` (alternative `docker image ls`) outputs all local images including file size, tag, and image ID.

[![Image: Overview of all images on the local system](https://www.ionos.ca/digitalguide/fileadmin/_processed_/3/9/csm_sudo-docker-images-empty_9806635619.webp "Overview of all images on the local system")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/sudo-docker-images-empty.png) The overview displays the images hello-world and docker/whalesay If you start a container, the underlying image is downloaded as a copy from the repository and permanently stored on your computer. This saves you time if you want to access the image at a later time. A new download is only initiated if the image source changes, for example, if a current version is available in the repository.

#### Display all containers on the local system

If you want to output an **overview of all containers** that are running on your system or have been run in the past, use the command line directive `docker ps` in combination with the option `--all` (short: `-a`):

```bash
sudo docker ps -a
```

[![Image: Overview of all containers on the local system](https://www.ionos.ca/digitalguide/fileadmin/_processed_/5/a/csm_sudo-docker-ps-a-english_74f680383e.webp "Overview of all containers on the local system")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/sudo-docker-ps-a-english.png) The overview shows all containers that have been launched on the Docker engine The terminal output contains information like the respective **container ID**, the underlying **image**, the **command** run when the container was started, the **time** when the container was started, and the **status**.

If you only want to show the containers that are currently running on your system, use the command line directive `docker ps` without any other options:

```bash
sudo docker ps
```

Currently, though, there should be no running containers on your system.

#### Create Docker images

Not that our Docker tutorial has shown you how to find images in the Docker hub, download them, and run them on any system with the Docker engine installed. But with Docker, you won’t only be able to access the extensive range of apps available in the registry. The platform also offers a wide range of options for **creating your own images** and sharing them with other developers.

In the introductory chapters of this Docker tutorial, you already learned that each Docker image is based on a **Dockerfile**. You can imagine Dockerfiles as a kind of **building template for images**. These are simple text files that contain all the instructions Docker needs to create an image. In the following steps, you’ll learn how to write this type of Dockerfile and instruct Docker to use this as the basis for your own image.

1. **Create new directory**: The Docker developer team recommends creating a new directory for each Dockerfile. Directories are easily created under Linux in the terminal. Use the following command line directive to create a directory with the name *mydockerbuild*:

```bash
mkdir mydockerbuild
```

[![Image: Ubuntu terminal: The command mkdir](https://www.ionos.ca/digitalguide/fileadmin/_processed_/4/8/csm_mkdir-mydockerbuild-english_b8f27a8820.webp "Ubuntu terminal: The command mkdir")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/mkdir-mydockerbuild-english.png) Create new directories with the command mkdir 2. **Navigate in the new directory**: Use the command `cd` to navigate in the newly created working directory.

```bash
cd mydockerbuild
```

[![Image: Ubuntu terminal: The command cd](https://www.ionos.ca/digitalguide/fileadmin/_processed_/6/d/csm_cd-mydockerbuild-english_93ecadd291.webp "Ubuntu terminal: The command cd")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/cd-mydockerbuild-english.png) With the help of the cd command, switch to another working directory 3. **Create new text file**: You can also easily create text files via the terminal with Ubuntu. To do this, use an editor like Nano or [Vim](https://www.ionos.ca/digitalguide/server/tools/linux-editor-effective-code-editing-with-vim/). Create a text file with the name *Dockerfile* in the *mydockerbuild* directory.

```bash
nano Dockerfile
```

[![Image: Ubuntu terminal: Create text files with Nano](https://www.ionos.ca/digitalguide/fileadmin/_processed_/2/4/csm_nano-dockerfile-empty_b2b1b6195b.webp "Ubuntu terminal: Create text files with Nano")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/nano-dockerfile-empty.png) The text editor Nano is preinstalled on all Ubuntu versions 4. **Write Dockerfile**: The newly created text file serves as a building plan for your self-developed image. Instead of programming the image from the ground up, in this Docker tutorial we’ll use the demo image *docker/whalesay* as a template. This is integrated using the command *FROM* in your Dockerfile. Use the tag *:latest* to point to the newest version of the image.

```none
FROM docker/whalesay:latest
```

So far, the way that *docker/whalesay* works is by you putting words into its mouth. In the terminal, the exact text that you entered is displayed in combination with the command to start the container. But it would be more interesting if the script **automatically** generated new text output. This can be done, for example, by using the *fortunes* program available on every Linux system. The basic function of *fortunes* is to generate fortune cookie sayings and humorous aphorisms. Use the following command to update your current local package index and install *fortunes*:

```none
RUN apt-get -y update && apt-get install -y fortunes
```

Then define a *CMD* statement. This is executed after the *RUN* command, unless it’s been overwritten by the call (`docker run image CMD`). Use the following command to run the *fortunes* program with the `-a` option (“Choose from all databases”) and display the output via the *cowsay* program in the terminal:

```none
CMD /usr/games/fortune -a | cowsay
```

Your Dockerfile should look as follows:

```none
FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
```

Note: **Commands** within a Dockerfile are **always single-spaced** and always start with a keyword. The underlying syntax is case-insensitive so it doesn’t matter whether you write in upper- or lowercase. A consistent capitalization of keywords has been established, though.

[![Image: The text editor Nano in the Ubuntu terminal](https://www.ionos.ca/digitalguide/fileadmin/_processed_/b/b/csm_nano-dockerfile-full_bd1796f06d.webp "The text editor Nano in the Ubuntu terminal")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/nano-dockerfile-full.png) Control the text editor Nano via the key combinations given in the footer 1. **Save text file**: Save your entry. If you’re using the Nano editor, save with the key combination \[CTRL\] + \[O\] and confirm with \[ENTER\]. Nano gives you the message that three lines have been written to the selected file. Close the text editor with the key combination \[CTRL\] + \[X\].
2. **Create image as Dockerfile**: To create an image from a Dockerfile, navigate first to the directory where the text file is located. Start the image creation with the command line directive `docker build`. If you want to individually name the image or provide it with a tag, use the option `-t` followed by the desired combination of label and tag. The standard format is `name:tag`.

In the current example, an image with the name *docker-whale* should be created:

```bash
docker build -t docker-whale .
```

The final **period** indicates that the underlying Dockerfile is found in the selected directory. You also have the option to specify a file path or a URL for the source files.

The *build* process starts as soon as the command is confirmed with \[ENTER\]. First, the Docker daemon checks whether it has all the files it needs to create the image. In Docker terminology, this is summarized under the term “context”.

Then, the *docker/whalesay* image with the tag *:latest* is located:

If the required context for the image creation already exists in its entirety, then the Docker daemon starts the image templated attached via *FROM* in a temporary container and moves to the next command in the *Dockerfile*. In the current example, this is the *RUN* command, which causes the *fortunes* program to be installed.

At the end of each step of the image creation process, Docker gives you an **ID for the corresponding layer** that’s created in the step. This means that each line in the underlying Dockerfile corresponds to a layer of the image built on it.

When the *RUN* command is finished, the Docker daemon stops the container created for it, removes it, and starts a new temporary container for the layer of the CMD statement. At the end of the creation process, this temporary container is also terminated and removed. Docker gives you the ID of the new image:

```none
Successfully built a8f2048c9ab8
```

[![Image: Ubuntu terminal: Status message during image creation](https://www.ionos.ca/digitalguide/fileadmin/_processed_/f/6/csm_sudo-docker-build-whale-english_d6b1eb3cf7.webp "Ubuntu terminal: Status message during image creation")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/sudo-docker-build-whale-english.png) Docker images are created in multiple layers Your newly created image can be found under the name *docker-whale* in the overview of your locally saved images.

```bash
sudo docker images
```

[![Image: Ubuntu terminal: Overview of all images](https://www.ionos.ca/digitalguide/fileadmin/_processed_/3/9/csm_docker-images-new-docker-whale_4a46337253.webp "Ubuntu terminal: Overview of all images")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-images-new-docker-whale.png) The newly created image in the image overview To start a container from your newly created image, use the command line directive `sudo docker run` in combination with the name of the image:

```bash
sudo docker run docker-whale
```

If the image was created correctly from the Dockerfile, your whale should now inspire you with more or less wise words. Note: Every time you restart the container, a new phrase is generated.

[![Image: Container based on docker-whale: Text output in the terminal](https://www.ionos.ca/digitalguide/fileadmin/_processed_/1/1/csm_sudo-run-docker-whale-fortunes-english_3bfb9d5385.webp "Container based on docker-whale: Text output in the terminal")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/sudo-run-docker-whale-fortunes-english.png) Thanks to fortunes, the ASCII whale now provides witty or wise phrases  Tip You can learn how to [create Docker images](https://www.ionos.ca/digitalguide/server/know-how/creating-docker-images/) in even more detail in our separate article on the topic.

#### Tag Docker images and upload them to Docker hub

If you want to upload your custom *docker-whale* image to the hub and make it available to either the community or a workgroup, you first need to link it with a repository of the same name in your own personal namespace. In the Docker terminology, this step is known as **tagging**.

To publish an image in the Docker hub, proceed as follows:

1. **Create a repository**: Log in to the Docker hub using your Docker ID and personal password and create a public repository with the name *docker-whale*.

[![Image: The Docker hub: Entry form for creating a repository](https://www.ionos.ca/digitalguide/fileadmin/_processed_/3/3/csm_docker-hub-create-docker-whale-repo_1266f7d9ea.webp "The Docker hub: Entry form for creating a repository")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-hub-create-docker-whale-repo.png) Create a repository for your custom image / Source: hub.docker.com 2. **Determine the image ID**: Determine the ID of your custom image *docker-whale* using the command line directive `docker images`.

[![Image: Overview of all local images in the Ubuntu terminal](https://www.ionos.ca/digitalguide/fileadmin/_processed_/5/a/csm_sudo-docker-images-id-english_265f2f9d16.webp "Overview of all local images in the Ubuntu terminal")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/sudo-docker-images-id-english.png) The command docker images lists all images that are saved on your system In our case the image ID is *a8f2048c9ab8*. We need this for tagging in the next step.

3. **Tag the image**: Tag the *docker-whale* image using the command line program `docker tag`:

```bash
sudo docker tag [Image-ID][Docker-ID]/[Image-Name]:[TAG]
```

For the current example, the command line directive for tagging reads:

```bash
sudo docker tag a8f2048c9ab8 [Namespace]/docker-whale:latest
```

You can check whether you’ve correctly tagged your image or not using the `docker images` overview. The name of the repository should now include your Docker ID.

[![Image: Ubuntu terminal: Image overview before and after tagging](https://www.ionos.ca/digitalguide/fileadmin/_processed_/6/e/csm_sudo-docker-tag-docker-whale-english_d2345804e2.webp "Ubuntu terminal: Image overview before and after tagging")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/sudo-docker-tag-docker-whale-english.png) Link images with your Docker ID using the command docker tag 4. **Upload the image**: To upload the image, you first need to log in to the Docker hub. This can be done using the `docker login` command.

```bash
sudo docker login
```

The terminal then prompts you to enter your username (Docker ID) and password.

[![Image: Log in to the Docker hub via the Ubuntu terminal](https://www.ionos.ca/digitalguide/fileadmin/_processed_/3/3/csm_sudo-docker-login-english_77fe04ede0.webp "Log in to the Docker hub via the Ubuntu terminal")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/sudo-docker-login-english.png) Before you can upload an image to the Docker hub, you first need to log in If the login was successful, then use the command line directive `docker push` to upload your image into the newly created repository.

```bash
sudo docker push [Namespace]/docker-whale
```

The upload process should only take a few seconds. The current status is shown in the terminal.

[![Image: Ubuntu terminal: Status message of the image upload](https://www.ionos.ca/digitalguide/fileadmin/_processed_/c/a/csm_sudo-docker-push-whale-english_44b31ef5fd.webp "Ubuntu terminal: Status message of the image upload")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/sudo-docker-push-whale-english.png) After uploading, the image is available under the set tag latest in the Docker hub Log into the Docker hub via the browser to view the uploaded image.

[![Image: Docker hub: The repository [Namespace]/docker-whale in the detailed view](https://www.ionos.ca/digitalguide/fileadmin/_processed_/5/e/csm_docker-hub-push-result_56530d8ebc.webp "Docker hub: The repository [Namespace]/docker-whale in the detailed view")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-hub-push-result.png) The latest update of your repository is shown in the detailed view / Source: hub.docker.com If you want to upload more than one image per repository, use varying tags to offer your images in different versions. For example:

```none
[Namespace]/docker-whale:latest
[Namespace]/docker-whale:version1
[Namespace]/docker-whale:version2
```

An overview of the various image versions can be found in the Docker hub repository under the “Tags” tab.

[![Image: Docker hub: The “Tags” tab](https://www.ionos.ca/digitalguide/fileadmin/_processed_/3/9/csm_docker-hub-multiple-versions-tags_e6c43a478d.webp "Docker hub: The “Tags” tab")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/docker-hub-multiple-versions-tags.png) In the “Tags” tab, you’ll find all versions of an image / Source: hub.docker.com Images of different projects should be offered in separate repositories, though.

If the upload was successful, your custom image will now be available in the public repository to every Docker user across the globe.

1. **Test run**: Test the success of the upload by attempting a download of the image.

Note that the local version of the image needs to first be deleted in order to download a new copy with the same tag. Otherwise, Docker will report that the desired image already exists in the current version.

[![Image: The Image is up to date](https://www.ionos.ca/digitalguide/fileadmin/_processed_/f/0/csm_sudo-docker-pull-docker-whale-english_84e2e758c4.webp "The Image is up to date")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/sudo-docker-pull-docker-whale-english.png) If an image exists locally, the pull command is canceled To delete the local Docker image, use the command line directive `docker rmi` in combination with the corresponding image ID. This is determined, as usual, via `docker images`. If Docker logs a conflict, e.g. because an image ID is used in multiple repositories or is used in a container, reiterate your command with the option `--force` (*-f* for short) to **force a deletion**.

```bash
sudo docker rmi -f a8f2048c9ab8
```

[![Image: Command docker rmi in combination with the option -f (force)](https://www.ionos.ca/digitalguide/fileadmin/_processed_/b/f/csm_sudo-docker-rmi-remove-image_75b679b119.webp "Command docker rmi in combination with the option -f (force)")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/sudo-docker-rmi-remove-image.png) Use the command docker rmi in combination with the option -f to force a deletion Display an overview of all local images again:

```bash
sudo docker Images
```

The deleted elements should no longer appear in the terminal output. Now use the pull command given in the repository to download a **new copy of the image** from the Docker hub.

```bash
sudo docker pull [Namespace]/docker-whale
```

[![Image: Ubuntu terminal: Download from the Docker hub](https://www.ionos.ca/digitalguide/fileadmin/_processed_/4/8/csm_sudo-docker-pull-image-redownload_3dfb6af27f.webp "Ubuntu terminal: Download from the Docker hub")](https://www.ionos.ca/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/sudo-docker-pull-image-redownload.png) The previously published image is successfully downloaded ## Additional Docker topics and tutorials

The Docker universe is large and over time, a living [ecosystem has developed from Docker tools](https://www.ionos.ca/digitalguide/server/know-how/docker-tools-the-container-platform-eco-system/). Docker is particularly useful for administrators, especially if they’re operating complex applications with multiple containers in parallel on different systems. Docker offers diverse functions for the **orchestration** of clusters like these. You can find more information about this in our article on [Docker orchestration with Swarm and Compose](https://www.ionos.ca/digitalguide/server/know-how/docker-orchestration-with-swarm-and-compose/).

The Digital Guide has **additional tutorials** for working with Docker:

- [Setting up a Docker Repository](https://www.ionos.ca/digitalguide/server/know-how/setting-up-a-docker-repository/)
- [Docker Container Volumes](https://www.ionos.ca/digitalguide/server/know-how/docker-container-volumes/)
- [Docker: Backup and restore](https://www.ionos.ca/digitalguide/server/security/docker-backup/)
- [Installing and running Docker on a Linux server](https://www.ionos.ca/digitalguide/server/know-how/installing-and-running-docker-on-a-linux-server/)
- Docker Compose tutorial

Docker is suitable for **various application scenarios**. You can find the following tutorials in the Digital Guide:

- [Deploying WordPress in Docker containers](https://www.ionos.ca/digitalguide/server/know-how/wordpress-in-docker-containers/)
- [Run a VPN in a Docker container using SoftEther](https://www.ionos.ca/digitalguide/server/know-how/vpn-in-a-docker-container-using-softether/)
- [Nextcloud installation with Docker](https://www.ionos.ca/digitalguide/server/configuration/nextcloud-installation-with-docker/)
- [Install Portainer under Docker](https://www.ionos.ca/digitalguide/server/configuration/install-portainer-under-docker/)
- [Redis in Docker Containers](https://www.ionos.ca/digitalguide/server/know-how/redis-in-docker-containers/)
- [Valheim Docker server](https://www.ionos.ca/digitalguide/server/know-how/valheim-docker-server/)

Docker is not always the best choice for every application. One of our articles covers the most popular [Docker alternatives](https://www.ionos.ca/digitalguide/server/know-how/docker-alternatives-at-a-glance/). In addition, we have many articles available that compare Docker with other platforms:

- [Kubernetes vs. Docker](https://www.ionos.ca/digitalguide/server/know-how/kubernetes-vs-docker/)
- [Openshift vs. Docker](https://www.ionos.ca/digitalguide/server/know-how/openshift-vs-docker/)
- [Podman vs. Docker](https://www.ionos.ca/digitalguide/server/know-how/podman-vs-docker/)


This is a markdown version of: [https://www.ionos.ca/digitalguide/server/configuration/docker-tutorial-installation-and-first-steps/](https://www.ionos.ca/digitalguide/server/configuration/docker-tutorial-installation-and-first-steps/) for AI/LLM consumption.