Перейти к содержимому

Как запустить докер на убунту

  • автор:

Установка Docker Engine на Ubuntu Server

Данная статья предназначена для тех, кто искал подробное и понятное руководство о том, как установить Docker Engine на Ubuntu Server.

Docker – это система управления контейнерами, она позволяет “упаковать” приложение или веб-сайт со всем его окружением и зависимостями в контейнер, которым можно легко управлять. Например, переносить на другой сервер, масштабировать или обновлять.

В этом руководстве мы будем рассматривать тот случай, когда у вас уже есть сервер с установленной на нем операционной системой Ubuntu Server 20.04 LTS.

Подробно о том, как установить Ubuntu Server 20.04 LTS, вы можете прочитать в моем руководстве «Установка Ubuntu Server 20.04 LTS».

Кроме того, на сервер должен быть установлен OpenSSH, а также открыт 22 порт, чтобы иметь возможность подключаться к серверу по протоколу SSH.

Для установки OpenSSH на сервер вы можете воспользоваться командой:

Если вы планируете подключиться к серверу, используя операционную систему Windows, то можете воспользоваться PuTTY — свободно распространяемым клиентом для различных протоколов удаленного доступа, включая SSH, Telnet, rlogin.

В данном руководстве рассматривается подключение к серверу при помощи терминального эмулятора iTerm2, установленного на операционную систему macOS.

Подключаемся к серверу, на который планируется установить Docker Engine.

Загрузим установочный срипт Docker Engine с помощью команды:

Теперь запустим установку Docker Engine с помощью команды:

Теперь нужно убедиться, что Docker Engine установлен корректно. Для этого необходимо выполнить команду:

Судя по полученному сообщению, Docker Engine установлен корректно.

Далее можно добавить пользователя в группу «docker», чтобы использовать Docker Engine без «sudo» или необходимости переключаться на пользователя «root».

Добавим пользователя «ubuntu» в группу «docker» с помощью команды:

Узнать о том, как установить Docker Compose на Ubuntu Server, вы можете, прочитав «Установка Docker Compose на Ubuntu Server».

Install Docker Engine on Ubuntu

To get started with Docker Engine on Ubuntu, make sure you meet the prerequisites, then install Docker.

Prerequisites

OS requirements

To install Docker Engine, you need the 64-bit version of one of these Ubuntu versions:

  • Ubuntu Focal 20.04 (LTS)
  • Ubuntu Eoan 19.10
  • Ubuntu Bionic 18.04 (LTS)
  • Ubuntu Xenial 16.04 (LTS)

Docker Engine is supported on x86_64 (or amd64 ), armhf , arm64 , s390x (IBM Z), and ppc64le (IBM Power) architectures.

Uninstall old versions

Older versions of Docker were called docker , docker.io , or docker-engine . If these are installed, uninstall them:

It’s OK if apt-get reports that none of these packages are installed.

The contents of /var/lib/docker/ , including images, containers, volumes, and networks, are preserved. The Docker Engine package is now called docker-ce .

Supported storage drivers

Docker Engine on Ubuntu supports overlay2 , aufs and btrfs storage drivers.

Docker Engine uses the overlay2 storage driver by default. If you need to use aufs instead, you need to configure it manually. See use the AUFS storage driver

Installation methods

You can install Docker Engine in different ways, depending on your needs:

Most users set up Docker’s repositories and install from them, for ease of installation and upgrade tasks. This is the recommended approach.

Some users download the DEB package and install it manually and manage upgrades completely manually. This is useful in situations such as installing Docker on air-gapped systems with no access to the internet.

In testing and development environments, some users choose to use automated convenience scripts to install Docker.

Install using the repository

Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.

Set up the repository

Update the apt package index and install packages to allow apt to use a repository over HTTPS:

Add Docker’s official GPG key:

Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 , by searching for the last 8 characters of the fingerprint.

Use the following command to set up the stable repository. To add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below. Learn about nightly and test channels.

Note: The lsb_release -cs sub-command below returns the name of your Ubuntu distribution, such as xenial . Sometimes, in a distribution like Linux Mint, you might need to change $(lsb_release -cs) to your parent Ubuntu distribution. For example, if you are using Linux Mint Tessa , you could use bionic . Docker does not offer any guarantees on untested and unsupported Ubuntu distributions.

Install Docker Engine

Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:

Got multiple Docker repositories?

If you have multiple Docker repositories enabled, installing or updating without specifying a version in the apt-get install or apt-get update command always installs the highest possible version, which may not be appropriate for your stability needs.

To install a specific version of Docker Engine, list the available versions in the repo, then select and install:

a. List the versions available in your repo:

b. Install a specific version using the version string from the second column, for example, 5:18.09.1

Verify that Docker Engine is installed correctly by running the hello-world image.

This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

Docker Engine is installed and running. The docker group is created but no users are added to it. You need to use sudo to run Docker commands. Continue to Linux postinstall to allow non-privileged users to run Docker commands and for other optional configuration steps.

Upgrade Docker Engine

To upgrade Docker Engine, first run sudo apt-get update , then follow the installation instructions, choosing the new version you want to install.

Install from a package

If you cannot use Docker’s repository to install Docker Engine, you can download the .deb file for your release and install it manually. You need to download a new file each time you want to upgrade Docker.

Go to https://download.docker.com/linux/ubuntu/dists/ , choose your Ubuntu version, then browse to pool/stable/ , choose amd64 , armhf , arm64 , ppc64el , or s390x , and download the .deb file for the Docker Engine version you want to install.

Note: To install a nightly or test (pre-release) package, change the word stable in the above URL to nightly or test . Learn about nightly and test channels.

Install Docker Engine, changing the path below to the path where you downloaded the Docker package.

The Docker daemon starts automatically.

Verify that Docker Engine is installed correctly by running the hello-world image.

This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

Docker Engine is installed and running. The docker group is created but no users are added to it. You need to use sudo to run Docker commands. Continue to Post-installation steps for Linux to allow non-privileged users to run Docker commands and for other optional configuration steps.

Upgrade Docker Engine

To upgrade Docker Engine, download the newer package file and repeat the installation procedure, pointing to the new file.

Install using the convenience script

Docker provides convenience scripts at get.docker.com and test.docker.com for installing edge and testing versions of Docker Engine — Community into development environments quickly and non-interactively. The source code for the scripts is in the docker-install repository. Using these scripts is not recommended for production environments, and you should understand the potential risks before you use them:

  • The scripts require root or sudo privileges to run. Therefore, you should carefully examine and audit the scripts before running them.
  • The scripts attempt to detect your Linux distribution and version and configure your package management system for you. In addition, the scripts do not allow you to customize any installation parameters. This may lead to an unsupported configuration, either from Docker’s point of view or from your own organization’s guidelines and standards.
  • The scripts install all dependencies and recommendations of the package manager without asking for confirmation. This may install a large number of packages, depending on the current configuration of your host machine.
  • The script does not provide options to specify which version of Docker to install, and installs the latest version that is released in the “edge” channel.
  • Do not use the convenience script if Docker has already been installed on the host machine using another mechanism.

This example uses the script at get.docker.com to install the latest release of Docker Engine — Community on Linux. To install the latest testing version, use test.docker.com instead. In each of the commands below, replace each occurrence of get with test .

Warning:

Always examine scripts downloaded from the internet before running them locally.

If you would like to use Docker as a non-root user, you should now consider adding your user to the “docker” group with something like:

Remember to log out and back in for this to take effect!

Warning:

Adding a user to the “docker” group grants them the ability to run containers which can be used to obtain root privileges on the Docker host. Refer to Docker Daemon Attack Surface for more information.

Docker Engine — Community is installed. It starts automatically on DEB -based distributions. On RPM -based distributions, you need to start it manually using the appropriate systemctl or service command. As the message indicates, non-root users can’t run Docker commands by default.

Note:

To install Docker without root privileges, see Run the Docker daemon as a non-root user (Rootless mode).

Rootless mode is currently available as an experimental feature.

Upgrade Docker after using the convenience script

If you installed Docker using the convenience script, you should upgrade Docker using your package manager directly. There is no advantage to re-running the convenience script, and it can cause issues if it attempts to re-add repositories which have already been added to the host machine.

Uninstall Docker Engine

Uninstall the Docker Engine, CLI, and Containerd packages:

Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:

Name already in use

docs / engine / install / ubuntu.md

  • Go to file T
  • Go to line L
  • Copy path
  • Copy permalink
  • Open with Desktop
  • View raw
  • Copy raw contents Copy raw contents

Copy raw contents

Copy raw contents

To get started with Docker Engine on Ubuntu, make sure you meet the prerequisites, then install Docker.

To install Docker Engine, you need the 64-bit version of one of these Ubuntu versions:

  • Ubuntu Kinetic 22.10
  • Ubuntu Jammy 22.04 (LTS)
  • Ubuntu Focal 20.04 (LTS)
  • Ubuntu Bionic 18.04 (LTS)

Docker Engine is compatible with x86_64 (or amd64 ), armhf , arm64 , and s390x architectures.

Uninstall old versions

Older versions of Docker went by the names of docker , docker.io , or docker-engine . Uninstall any such older versions before attempting to install a new version:

It’s OK if apt-get reports that none of these packages are installed.

Images, containers, volumes, and networks stored in /var/lib/docker/ aren’t automatically removed when you uninstall Docker. If you want to start with a clean installation, and prefer to clean up any existing data, refer to the uninstall Docker Engine section.

You can install Docker Engine in different ways, depending on your needs:

Docker Engine comes bundled with Docker Desktop for Linux. This is the easiest and quickest way to get started.

You can also set up and install Docker Engine from Docker’s apt repository.

Install it manually and manage upgrades manually.

Using a convenience scripts. Only recommended for testing and development environments.

Install using the repository

Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.

Set up the repository

Update the apt package index and install packages to allow apt to use a repository over HTTPS:

Add Docker’s official GPG key:

Use the following command to set up the repository:

Install Docker Engine

Update the apt package index:

Receiving a GPG error when running apt-get update ?

Your default umask <: target="blank" rel="noopener" >may be incorrectly configured, preventing detection of the repository public key file. Try granting read permission for the Docker public key file before updating the package index:

Install Docker Engine, containerd, and Docker Compose.

  • Latest
  • Specific version

To install the latest version, run:

To install a specific version of Docker Engine, start by list the available versions in the repository:

Select the desired version and install:

Verify that the Docker Engine installation is successful by running the hello-world image:

This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.

You have now successfully installed and started Docker Engine. The docker user group exists but contains no users, which is why you’re required to use sudo to run Docker commands. Continue to Linux post-install to allow non-privileged users to run Docker commands and for other optional configuration steps.

Upgrade Docker Engine

To upgrade Docker Engine, follow the installation instructions, choosing the new version you want to install.

Install from a package

If you can’t use Docker’s apt repository to install Docker Engine, you can download the deb file for your release and install it manually. You need to download a new file each time you want to upgrade Docker Engine.

Select your Ubuntu version in the list.

Go to pool/stable/ and select the applicable architecture ( amd64 , armhf , arm64 , or s390x ).

Download the following deb files for the Docker Engine, CLI, containerd, and Docker Compose packages:

  • containerd.io_<version>_<arch>.deb
  • docker-ce_<version>_<arch>.deb
  • docker-ce-cli_<version>_<arch>.deb
  • docker-buildx-plugin_<version>_<arch>.deb
  • docker-compose-plugin_<version>_<arch>.deb

Install the .deb packages. Update the paths in the following example to where you downloaded the Docker packages.

The Docker daemon starts automatically.

Verify that the Docker Engine installation is successful by running the hello-world image:

This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.

You have now successfully installed and started Docker Engine. The docker user group exists but contains no users, which is why you’re required to use sudo to run Docker commands. Continue to Linux post-install to allow non-privileged users to run Docker commands and for other optional configuration steps.

Upgrade Docker Engine

To upgrade Docker Engine, download the newer package file and repeat the installation procedure, pointing to the new file.

Uninstall Docker Engine

Uninstall the Docker Engine, CLI, containerd, and Docker Compose packages:

Images, containers, volumes, or custom configuration files on your host aren’t automatically removed. To delete all images, containers, and volumes:

How To Install Docker on Ubuntu 20.04

Docker is a platform enabling users to package and run applications in containers. Containers are isolated, similar to virtual machines, but more portable and resource-friendly. The isolation allows for the execution of many containers simultaneously on a single host.

Docker uses a client-server architecture and relies on the Docker daemon to manage the containers.

In this tutorial, you will learn to install and use Docker on Ubuntu 20.04.

How to install Docker on Ubuntu 20.04 - Guide.

    .
  • A user account with administrator privileges.
  • Access to the terminal (Ctrl + Alt + T).

Installing Docker on Ubuntu

Ubuntu is the number one platform for managing Docker or Kubernetes containers. This is because Ubuntu runs the containers at scale, it is fast, secure, and open-source, powering millions of machines worldwide.

This article will cover two options for installing Docker on Ubuntu:

  • From the official Docker repository — ensuring the latest Docker version.
  • From the default Ubuntu repositories — providing a simpler installation.

Follow the steps below and install Docker on Ubuntu 20.04 using the method of your choice.

Important: Make sure to remove any older Docker installations before installing a new one. Removing previous Docker versions doesn’t delete the images, containers, volumes, or networks you have created. Run the following command to uninstall previous versions:

Installing Docker from the Official Repository (Option 1)

Install Docker from the official Docker repository to ensure you get the latest stable program version. To access the official Docker repository, add the new package source to Ubuntu and then install Docker. Follow the steps below:

Step 1: Update the Package Repository

Run the following command to update the system’s package repository and ensure the latest prerequisite packages are installed:

When prompted, enter your root password and press Enter to proceed with the update.

Step 2: Install Prerequisite Packages

The apt package manager requires a few prerequisite packages on the system to use packages over HTTPS. Run the following command to allow Ubuntu to access the Docker repositories over HTTPS:

Installing the prerequisite packages for Docker on Ubuntu.

The command above:

  • Allows apt to transfer files and data over https.
  • Allows the system to check security certificates.
  • Installs curl, a data-transfer utility.
  • Adds scripts for software management.
Step 3: Add GPG Key

A GPG key verifies the authenticity of a software package. Add the Docker repository GPG key to your system by running:

Adding the Docker GPG key to verify package authenticity.

The output should state OK , verifying the authenticity.

Step 4: Add Docker Repository

Run the following command to add the Docker repository to apt sources:

Adding the Docker official repository to the apt package manager.

The command adds the official Docker repository and updates the package database with the latest Docker packages.

Step 5: Specify Installation Source

Execute the apt-cache command to ensure the Docker installation source is the Docker repository, not the Ubuntu repository. The apt-cache command queries the package cache of the apt package manager for the Docker packages we have previously added.

Run the following command:

Specifying the Docker installation source.

The output states which version is the latest in the added source repository.

Step 6: Install Docker

Install Docker by running:

Installing Docker on Ubuntu using the official repository.

Wait for the installation process to complete.

Step 7: Check Docker Status

Check if Docker is installed, the daemon started, and the process is enabled to start on boot. Run the following command:

Checking the Docker daemon status.

The output states that the Docker daemon is up and running.

Installing Docker from the Default Repositories (Option 2)

Another way to install Docker on Ubuntu is to use the default Ubuntu repository. Although the installation process is more straightforward, the Docker package may be outdated. If you don’t care about having the latest Docker version, follow the steps below and install Docker using the default repository.

Step 1: Update the Repository

Ensure that the local system package repository is updated by running:

Enter the root password when prompted and wait for the process to finish.

Step 2: Install Docker

Run the following command to install Docker:

Installing Docker using the default Ubuntu repository.

Specifying the -y flag automatically answers yes to any prompt during the installation.

Step 3: Install Dependencies

Install all the Docker dependency packages by running the following command:

Installing Docker dependencies using the Snap package manager.

The command installs all the dependencies using the Snap package manager.

Step 4: Check Installation

Check whether Docker was properly installed by running the status command or checking the program version. To see the Docker daemon status, run:

Alternatively, check the program version by running:

Checking Docker program version.

How to Use Docker on Ubuntu

All Docker information, including the syntax, options, and commands, is available by running the docker command in the terminal:

Reading the Docker help file.

Start using Docker by downloading Docker images, creating containers, and managing Docker volumes.

Important: Docker commands can only be run with the sudo prefix on Ubuntu.

Working With Docker Images

Docker images are the base for building Docker containers. The images are located on Docker Hub, which is a Docker repository. The repository allows all users to host their images on Docker hub, resulting in many images to choose from, including applications and Linux distributions.

The sections below show different ways of working with Docker images.

Note: See how to update a Docker image or container to the latest version available.

Search for Docker Images

Search for available images on Docker Hub using the docker search command. The syntax is:

For [keyword] , specify the keyword you want to search for. For example, to show all Ubuntu images, run:

Searching for Docker images on Docker Hub.

The output is a list of all images containing the Ubuntu keyword. If the OFFICIAL column contains the [OK] parameter, the image was uploaded by the official company that developed the project.

Pull a Docker Image

After deciding which image you want, download it using the pull option. The syntax is:

For example, download the official Ubuntu image by running:

Pulling a Docker image.

After downloading the image, use it to spin up a container. Alternatively, trying to create a container from an image that hasn’t been downloaded causes Docker to download the image first and then create the container.

See Downloaded Images

Check which images you have downloaded by running:

Listing the downloaded Docker images.

The command outputs a list of all downloaded images on your machine. In our case, it is a Ubuntu and MySQL Docker image.

Working With Docker Containers

A Docker container is an isolated virtual environment created from a Docker image. Use an image you previously downloaded or specify its name in the docker run command to automatically download the image and create a container.

For example, use the hello-world image to download a test image and spin up a container. Run the following command:

Creating a test container in Docker on Ubuntu.

The command instructs Docker to download the image from Docker Hub and spin up a container. After creation, the «Hello from Docker» message appears, along with the explanation of how the container works, and then Docker shuts it down.

Note: Check out the best container practices in How to Manage Docker Containers, or see how to list, start, and stop Docker containers.

Run a Docker Container

Like in the test container created in the previous section, running a Docker container utilizes the run subcommand. The syntax for creating a new Docker container is as follows:

For [image-name] , specify the name of the image to use as a base for the container. When creating a new container, Docker assigns it a unique name. Alternatively, start a new container and give it a name of your choice by passing the —name switch:

Note: The docker run command is an alias for docker container run . Before Docker version 1.13, only the docker run command was used, but later it was refactored to have the form docker [COMMAND] [SUBCOMMAND] , where the [COMMAND] is container , and the [SUBCOMMAND] is run .

For example, run the following command to create a container using the Ubuntu image we pulled earlier:

Running a Docker container in non-interactive mode.

The command creates a container from the specified image, but it is in non-interactive mode. To obtain interactive shell access to the container, specify the -i and -t switches. For example:

Running a Docker container in interactive mode.

The terminal changes, stating that it is operating within the container, identifying it via the container ID. Use the container ID to remove, start, or stop the container.

After running the container in interactive mode, pass any command normally to interact with the system. Also, the access is root, so there is no need for sudo . Any changes made inside the container apply only to that container.

Exit the container by running the exit command in the prompt.

Note: For additional security, learn how to SSH into a running Docker container.

View Docker Containers

An active Docker container is a container that is currently running. Listing containers is useful as it outputs the unique ID and name required when starting, stopping, or removing a container.

To see only the active Docker containers, run:

Listing active Docker containers on Ubuntu.

The command outputs a list of active containers. If there are no containers in the list, they have all been shut down, but they still exist in the system.

To list all containers, including the inactive ones, add the -a flag:

Listing all containers in Ubuntu.

The command outputs all existing containers and their details, including the container ID, image, command, creation time, the status, ports, and the unique name.

Alternatively, show only the latest container by passing the -l flag:

Listing only the latest Docker container.

Start a Docker Container

Start a stopped container using the docker start command. The syntax is:

Provide either the container ID or the container name. The container name is a unique name that Docker assigns to the container during creation. Obtain the ID and name by listing all containers.

For example, the following command starts the Ubuntu container we previously created:

Stop a Docker Container

Stop a running Docker container using the docker stop command. The syntax is:

For example, to stop the running Ubuntu container, run:

Remove a Docker Container

Remove an unnecessary Docker container using the docker rm command. The syntax is:

For example, the following command removes the hello-world test container we previously created:

Note: Pass the —rm switch when creating a container to remove the container automatically when stopped.

Working With Docker Volumes

A Docker volume is a filesystem mechanism allowing users to preserve data generated and used by Docker containers. The volumes ensure data persistence and provide a better alternative to persisting data in a container’s writable layer because they don’t increase the Docker container size.

Use Docker volumes for databases or other stateful applications. Since the volumes are stored on the host, they don’t depend on the container but allow for easy data backups and sharing between multiple containers.

Create a Docker Volume

Create a Docker volume using the following syntax:

For [volume_name] , specify a unique name for your volume.

Creating an example volume in Docker.

Remove a Docker Volume

Remove a Docker volume using the following syntax:

Check out our tutorial for detailed information and instructions on using Docker volumes.

Docker Network Commands

Networking is very tightly integrated with Docker and running Docker containers. Docker networking commands allow users to create and manage their networks within a container. The following table shows the basic subcommands used for Docker network management:

Listing all existing networks in Docker.

Since this is a fresh installation, the output shows only a few automatically created networks. The information includes the unique network ID, an arbitrary name for each network, the network driver, and the network scope.

To obtain more detail on a particular network, use the inspect subcommand. For example, to get detailed information on the bridge network, run:

Viewing a network

The output includes details such as all the containers attached to the network, the particular bridge it is connected to, and much more.

For more detail on Docker commands, refer to our Docker commands tutorial, which includes a downloadable cheat sheet with all the important commands in one place.

This guide showed how to install Docker on Ubuntu 20.04 and start using Docker to download images and spin up containers. For more Docker tutorials, see the difference between Docker add and copy, Docker cmd and entrypoint commands, or learn to run the ELK stack on Docker.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Luxury Car Rental in Miami | Reserve a Premium Vehicle with RealCar