In our Docker tutorial, we introduce you to the Docker vir­tu­al­isa­tion platform and show you how to use Docker on your Ubuntu 22.04 system using easy-to-follow in­struc­tions.

Free VPS Trial
Try a virtual server risk-free for 30 days

Try out your VPS for 30 days. If you're not satisfied, we'll fully reimburse you.

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 al­tern­at­ive for the emulation of hardware com­pon­ents based on virtual machines (VMs).

While tra­di­tion­al hardware vir­tu­al­isa­tion is based on launching multiple guest systems on a common host system, Docker ap­plic­a­tions are run as isolated processes on the same system with the help of con­tain­ers. This is called container-based vir­tu­al­isa­tion, also referred to as operating-system-level vir­tu­al­isa­tion.

Image: Virtual machines and software containers in comparison
While each virtual machine launches its own operating system, Docker con­tain­ers share the core of the host system

One big advantage of container-based vir­tu­al­isa­tion is that ap­plic­a­tions with different re­quire­ments can run in isolation from one another without requiring the overhead of a separate guest system. Ad­di­tion­ally, with con­tain­ers, ap­plic­a­tions can be deployed across platforms and in different in­fra­struc­tures without having to adapt to the hardware or software con­fig­ur­a­tions of the host system.

Docker is the most popular software project that provides users with container-based vir­tu­al­isa­tion tech­no­logy. The open-source platform is based on three basic com­pon­ents. In order to execute con­tain­ers, users only need the Docker engine as well as special Docker images, which can be obtained via the Docker hub or created them­selves.

Tip

Docker con­tain­ers and images are mostly generic, but can be highly cus­tom­ised as needed. You can read more about it in our article on Docker con­tain­ers.

Docker images

Similar to virtual machines, Docker con­tain­ers are based on Docker images. An image is a read-only template that contains all in­struc­tions 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 Dock­er­file. If a container is to be launched on a system, then first a package with the re­spect­ive image is loaded, as long as it doesn’t exist locally. The loaded image provides the necessary file system including all para­met­ers 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 re­pos­it­or­ies, 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 es­tab­lished open-source projects. Images uploaded to the private section of the registry aren’t ac­cess­ible publicly and so can be shared, for example, within a company’s internal circle or with friends or ac­quaint­ances. The Docker hub can be accessed on hub.docker.com.

The Docker engine

At the heart of the Docker project is the Docker engine. This is an open-source client server ap­plic­a­tion, which is available to all users in the current version on all es­tab­lished platforms.

The basic ar­chi­tec­ture of the Docker engine is divided between three com­pon­ents: A daemon with server functions, a pro­gram­ming interface (API) based on the pro­gram­ming paradigm REST (Rep­res­ent­a­tion­al 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 back­ground of the host system, and is used for the central control of the Docker engine. This function creates and manages all images, con­tain­ers, or networks.

  • REST-API: The REST-API specifies a set of in­ter­faces that allow other programs to com­mu­nic­ate with the Docker daemon and give it in­struc­tions. One of these programs is the terminal of the operating system.

  • Terminal: As a client program, Docker uses the operating system’s terminal. This, in­teg­rated 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 (ab­bre­vi­ated to Docker CE), but the official doc­u­ment­a­tion and Docker re­pos­it­or­ies mostly still use the old name. In addition to Docker CE, there is also Docker En­ter­prise Edition (Docker EE), which has some premium features. However, it is not free and is more suitable for en­ter­prises.

With Docker commands, user software con­tain­ers can be started, stopped, and managed directly from the terminal. The Daemon is addressed via the command docker and in­struc­tions 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 con­nec­tion being es­tab­lished, com­mu­nic­a­tion between the client and the server takes place via the REST-API, via UNIX sockets, or via a network interface.

The following graphic il­lus­trates the interplay of the in­di­vidu­al Docker com­pon­ents with the example commands docker build, docker pull, and docker run:

Image: Schematic representation of the Docker architecture
The Docker ar­chi­tec­ture is based on the co­oper­a­tion of the client (terminal

The command docker build instructs the Docker daemon to create an image (dotted line). For this, a cor­res­pond­ing Dock­er­file needs to be available. If the image isn’t to be created, but instead loaded from a re­pos­it­ory in the Docker hub, then the docker pull command is used (dashed line). If the Docker daemon is in­struc­ted via docker run to launch a container, the back­ground program checks whether or not the cor­res­pond­ing container image is locally available. If it is, then the container is run (solid line). If the daemon can’t find the image, it auto­mat­ic­ally initiates a pull from the re­pos­it­ory.

Dedicated Server
Per­form­ance through in­nov­a­tion
  • En­ter­prise hardware
  • Con­fig­ur­able hardware equipment
  • ISO-certified data centres

Working with Docker

Now it’s time to get familiar with the container platform ap­plic­a­tions. If you have not yet installed the Docker engine, you can do so via the Linux Terminal. You can find in­struc­tions on how to do this in our article entitled ‘Install Docker on Ubuntu 22.04’. Learn below how to control the Docker Engine from the terminal, what the Docker Hub can do for you, and why Docker con­tain­ers could re­volu­tion­ise the way you work with ap­plic­a­tions.

Tip

If you want to install Docker on another Linux dis­tri­bu­tion or Windows, the following in­struc­tions will help:

How to control the Docker engine

Since version 16.04, Ubuntu has used the back­ground program systemd(short for ‘system daemon’) to manage processes.Systemdis an init process, also used on other Linux dis­tri­bu­tions like RHEL, CentOS, or Fedora. Typically,systemreceives the process ID 1. As the first process of the system, the daemon is re­spons­ible for starting, mon­it­or­ing, and ending all following processes. For previous Ubuntu versions (14.10 and older), the back­ground programupstart takes over this function.

The Docker daemon can also be con­trolled via systemd. In the standard in­stall­a­tion, the container platform is con­figured so that the Daemon auto­mat­ic­ally starts when the system is booted up. This default setting can be cus­tom­ised 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:

systemctl [OPTION] [COMMAND]
bash

Some commands refer to specific resources (for example, Docker). In the ter­min­o­logy of systemd, these are referred to as units. In this case, the command results from the re­spect­ive in­struc­tion and the name of the unit to be addressed.

If you would like to activate the autostart of the Docker daemon (enable) or de­ac­tiv­ate it (disable), use the command line tool systemctl with the following commands:

sudo systemctl enable docker
sudo systemctl disable docker
bash

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

sudo systemctl status docker
bash

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

Image: The status query via systemctl shows: The Docker engine is active (running)
Status query via systemctl: The Docker Engine is active (running)

If your Docker engine is currently de­ac­tiv­ated, then you’ll receive the status de­clar­a­tion inactive (dead). In this case, you need to manually launch the Docker daemon to run con­tain­ers.

Image: The status query via systemctl shows: The Docker engine is inactive (dead)
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 de­ac­tiv­ated daemon, use systemctl in com­bin­a­tion with the command start:

sudo systemctl start docker
bash

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

sudo systemctl stop docker
bash

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

sudo systemctl restart docker
bash

How to use the Docker hub

If the Docker engine rep­res­ents 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 in­stall­a­tion.

The online service offers diverse official re­pos­it­or­ies with more than 100,000 free apps. Users have the option to create an image archive and use them col­lect­ively with work groups. In addition to the pro­fes­sion­al support offered by the de­vel­op­ment team, beginners can find con­nec­tions to the user community here. A forum for community support is available on GitHub.

Image: The Docker hub: Registration
Create your personal Docker ID for free by re­gis­ter­ing / Source: hub.docker.com

Re­gis­ter­ing in the Docker hub

Re­gis­ter­ing in the Docker hub is free. Users just need an email address and their chosen Docker ID. This serves as a personal re­pos­it­ory 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.

The re­gis­tra­tion process is comprised of five steps:

  1. Choose your Docker ID: As the first part of the ap­plic­a­tion, 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 re­gis­tra­tion with Docker hub via email.
  3. Choose a password: Choose a secret password.
  4. Submit your re­gis­tra­tion: Click on ‘Sign up’ to submit your re­gis­tra­tion. Once the data has been fully trans­mit­ted, 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 veri­fic­a­tion link.

The online services of the Docker project are im­me­di­ately available following your re­gis­tra­tion in the browser. Here you can create re­pos­it­or­ies and work­groups, or search the Docker hub for public resources using ‘Explore’.

Image: Dashboard of the Docker hub
Select and set re­pos­it­or­ies and work­groups 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 de­scrip­tion of the command can be found in the Docker doc­u­ment­a­tion.

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

Create re­pos­it­or­ies in the Docker hub

The free Docker hub account contains one private re­pos­it­ory, and offers the pos­sib­il­ity to create any number of public re­pos­it­or­ies. If you should need more private re­pos­it­or­ies, you can unlock these with a paid upgrade.

To create a re­pos­it­ory, proceed as follows:

  1. Choose a namespace: Newly created re­pos­it­or­ies are auto­mat­ic­ally assigned to the namespace of your Docker ID. You also have the option to enter the ID of an or­gan­isa­tion that you belong to.
  2. Label the re­pos­it­ory: Enter a name for the newly created re­pos­it­ory.
  3. Add a de­scrip­tion: Add a short de­scrip­tion for your re­pos­it­ory.
  4. Set vis­ib­il­ity: Decide whether the re­pos­it­ory should be publicly visible (public) or only ac­cess­ible by you or your or­gan­isa­tion (private).

Confirm your entries by clicking ‘Create’.

Image: The Docker hub: Input screen for creating a repository
Your re­pos­it­or­ies are auto­mat­ic­ally created in the namespace of your Docker ID / Source: hub.docker.com

Create teams and or­gan­isa­tions

With the hub, Docker provides a cloud-based platform on which self-created images are centrally managed and con­veni­ently shared with work­groups. In the Docker ter­min­o­logy, these are called or­gan­isa­tions. Just like user accounts, or­gan­isa­tions receive in­di­vidu­al IDs via which images can be provided and down­loaded. Rights and roles within an or­gan­isa­tion can be assigned via teams. For example, users assigned to the ‘Owners’ team have the authority to create private or public re­pos­it­or­ies and assign access rights.

Work­groups can also be created and managed directly via the dashboard. Further in­form­a­tion about or­gan­isa­tions and teams can be found in the Docker doc­u­ment­a­tion.

Working with images and con­tain­ers

As the first point of contact for official Docker resources, the Docker hub is our starting point for this in­tro­duc­tion to handling images and con­tain­ers. 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
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 re­pos­it­ory for this image.

Docker re­pos­it­or­ies 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 re­pos­it­ory, and the time of the last upload (last pushed).

Image: Web view of a Docker repository
In the re­pos­it­ory, users generally find all in­form­a­tion that is needed to use an image / Source: hub.docker.com

Each Docker re­pos­it­ory also offers the following info boxes:

  1. De­scrip­tion: Detailed de­scrip­tion, usually including dir­ec­tions for use
  2. Docker pull command: Command line directive used to download the image from the re­pos­it­ory (pull)
  3. Owner: In­form­a­tion about the creator of the re­pos­it­ory
  4. Comments: Comment section at the end of the page

The in­form­a­tion boxes of the re­pos­it­ory show that whalesay is a modi­fic­a­tion 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:

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

The command docker pull instructs the daemon to load an image from the re­pos­it­ory. 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 in­di­vidu­al iden­ti­fic­a­tion 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:

docker pull docker/whalesay
bash

In general, you can skip this step. If you’d like to launch a container, the Docker daemon auto­mat­ic­ally downloads the images from the re­pos­it­ory that it can’t find on the local system.

Launch Docker images as con­tain­ers

To start a Docker image, use the command docker run:

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

The only ob­lig­at­ory 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 auto­mat­ic­ally when the container is started) is over­writ­ten. Other optional con­fig­ur­a­tions can be defined through ad­di­tion­al arguments (ARG…). This makes it possible, for example, to add users or to transfer en­vir­on­ment variables.

Use the command line directive

docker run docker/whalesay cowsay boo
bash

to download the existing Perl script as an image and run in a container. You’ll see that whalesay differs sig­ni­fic­antly from the source script.

Image: Terminal output of the container docker/whalesay: The whale says ‘boo’
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 re­pos­it­ory is initiated. Then the daemon starts the modified cowsay program. If this has run through, then the container is ended auto­mat­ic­ally.

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.

sudo docker run docker/whalesay cowsay What did the shark say to the whale? What are you blubbering about?
bash
Image: Terminal output of the container docker/whalesay: A whale with an individual message
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 down­loaded a par­tic­u­lar image, you can access an overview of all the images on your local system. Use the following command line directive:

sudo docker image
bash

The command docker images (al­tern­at­ive docker image ls) outputs all local images including file size, tag, and image ID.

Image: Overview of all images on the local system
The overview displays the images hello-world and docker/whalesay

If you start a container, the un­der­ly­ing image is down­loaded as a copy from the re­pos­it­ory and per­man­ently 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 re­pos­it­ory.

Display all con­tain­ers on the local system

If you want to output an overview of all con­tain­ers that are running on your system or have been run in the past, use the command line directive docker ps in com­bin­a­tion with the option --all (short: -a):

sudo docker ps -a
bash
Image: Overview of all containers on the local system
The overview shows all con­tain­ers that have been launched on the Docker engine

The terminal output contains in­form­a­tion like the re­spect­ive container ID, the un­der­ly­ing 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 con­tain­ers that are currently running on your system, use the command line directive docker ps without any other options:

sudo docker ps
bash

Currently, though, there should be no running con­tain­ers 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 de­velopers.

In the in­tro­duct­ory chapters of this Docker tutorial, you already learned that each Docker image is based on a Dock­er­file. You can imagine Dock­er­files as a kind of building template for images. These are simple text files that contain all the in­struc­tions Docker needs to create an image. In the following steps, you’ll learn how to write this type of Dock­er­file and instruct Docker to use this as the basis for your own image.

  1. Create new directory: The Docker developer team re­com­mends creating a new directory for each Dock­er­file. Dir­ect­or­ies are easily created under Linux in the terminal. Use the following command line directive to create a directory with the name mydock­er­build:
mkdir mydockerbuild
bash
Image: Ubuntu terminal: The command mkdir
Create new dir­ect­or­ies with the command mkdir
  1. Navigate in the new directory: Use the command cd to navigate in the newly created working directory.
cd mydockerbuild
bash
Image: Ubuntu terminal: The command cd
With the help of the cd command, switch to another working directory
  1. 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. Create a text file with the name Dock­er­file in the mydock­er­build directory.
nano Dockerfile
bash
Image: Ubuntu terminal: Create text files with Nano
The text editor Nano is pre­in­stalled on all Ubuntu versions
  1. Write Dock­er­file: The newly created text file serves as a building plan for your self-developed image. Instead of pro­gram­ming the image from the ground up, in this Docker tutorial we’ll use the demo image docker/whalesay as a template. This is in­teg­rated using the command FROM in your Dock­er­file. Use the tag :latest to refer to the newest version of the image.
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 com­bin­a­tion with the command to start the container. But it would be more in­ter­est­ing if the script auto­mat­ic­ally 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:

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 over­writ­ten 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:

CMD /usr/games/fortune -a | cowsay

Your Dock­er­file should look as follows:

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

Note: Commands within a Dock­er­file are always single-spaced and always start with a keyword. The un­der­ly­ing syntax is case-in­sens­it­ive so it doesn’t matter whether you write in upper- or lowercase. A con­sist­ent cap­it­al­isa­tion of keywords has been es­tab­lished, though.

Image: The text editor Nano in the Ubuntu terminal
Control the text editor Nano via the key com­bin­a­tions given in the footer
  1. Save text file: Save your entry. If you’re using the Nano editor, save with the key com­bin­a­tion [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 com­bin­a­tion [CTRL] + [X].

  2. Create image as Dock­er­file: To create an image from a Dock­er­file, 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 in­di­vidu­ally name the image or provide it with a tag, use the option -t followed by the desired com­bin­a­tion of label and tag. The standard format is name:tag.

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

docker build -t docker-whale .
bash

The final period indicates that the un­der­ly­ing Dock­er­file 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 ter­min­o­logy, this is sum­mar­ised 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 Dock­er­file. 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 cor­res­pond­ing layer that’s created in the step. This means that each line in the un­der­ly­ing Dock­er­file cor­res­ponds 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 ter­min­ated and removed. Docker gives you the ID of the new image:

Successfully built a8f2048c9ab8
Image: Ubuntu terminal: Status message during image creation
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.

sudo docker images
bash
Image: Ubuntu terminal: Overview of all images
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 com­bin­a­tion with the name of the image:

sudo docker run docker-whale
bash

If the image was created correctly from the Dock­er­file, 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
Thanks to fortunes, the ASCII whale now provides witty or wise phrases
Tip

You can learn how to create 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 re­pos­it­ory of the same name in your own personal namespace. In the Docker ter­min­o­logy, this step is known as tagging.

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

  1. Create a re­pos­it­ory: Log in to the Docker hub using your Docker ID and personal password and create a public re­pos­it­ory with the name docker-whale.
Image: The Docker hub: Entry form for creating a repository
Create a re­pos­it­ory for your custom image / Source: hub.docker.com
  1. 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
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.

  1. Tag the image: Tag the docker-whale image using the command line program docker tag according to the following:
sudo docker tag [Image-ID][Docker-ID]/[Image-Name]:[TAG]
bash

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

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

You can check whether you’ve correctly tagged your image or not using the docker images overview. The name of the re­pos­it­ory should now include your Docker ID.

Image: Ubuntu terminal: Image overview before and after tagging
Link images with your Docker ID using the command docker tag
  1. 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.
sudo docker login
bash

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

Image: Log in to the Docker hub via the Ubuntu terminal
Before you can upload an image to the Docker hub, you first need to log in

If the login was suc­cess­ful, then use the command line directive docker push to upload your image into the newly created re­pos­it­ory.

sudo docker push [Namespace]/docker-whale
bash

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
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
The latest update of your re­pos­it­ory is shown in the detailed view / Source: hub.docker.com

If you want to upload more than one image per re­pos­it­ory, use varying tags to offer your images in different versions. For example:

[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 re­pos­it­ory under the ‘Tags’ tab.

Image: Docker hub: The ‘Tags’ tab
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 re­pos­it­or­ies, though.

If the upload was suc­cess­ful, your custom image will now be available in the public re­pos­it­ory to every Docker user across the globe.

  1. Test run: Test the success of the upload by at­tempt­ing 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
If an image exists locally, the pull command is cancelled

To delete the local Docker image, use the command line directive docker rmi in com­bin­a­tion with the cor­res­pond­ing image ID. This is de­term­ined, as usual, via docker images. If Docker logs a conflict, e.g. because an image ID is used in multiple re­pos­it­or­ies or is used in a container, reiterate your command with the option --force (-f for short) to force a deletion.

sudo docker rmi -f a8f2048c9ab8
bash
Image: Command docker rmi in combination with the option -f (force)
Use the command docker rmi in com­bin­a­tion with the option -f to force a deletion

Display an overview of all local images again:

sudo docker Images
bash

The deleted elements should no longer appear in the terminal output. Now use the pull command given in the re­pos­it­ory to download a new copy of the image from the Docker hub.

sudo docker pull [Namespace]/docker-whale
bash
Image: Ubuntu terminal: Download from the Docker hub
The pre­vi­ously published image is suc­cess­fully down­loaded

Ad­di­tion­al Docker topics and tutorials

The Docker universe is large and over time, a living ecosystem has developed from Docker tools. Docker is par­tic­u­larly useful for ad­min­is­trat­ors, es­pe­cially if they’re operating complex ap­plic­a­tions with multiple con­tain­ers in parallel on different systems. Docker offers diverse functions for the or­ches­tra­tion of clusters like these. You can find more in­form­a­tion about this in our article on Docker or­ches­tra­tion with Swarm and Compose.

The Digital Guide has ad­di­tion­al tutorials for working with Docker:

Docker is suitable for various ap­plic­a­tion scenarios. You can find the following tutorials in the Digital Guide:

Docker is not always the best choice for every ap­plic­a­tion. One of our articles covers the most popular Docker al­tern­at­ives. In addition, we have many articles available that compare Docker with other platforms:

Go to Main Menu