Install the Docker tutorial under Ubuntu

  • 2020-05-24 06:40:57
  • OfStack

Prior to installation, a number of prerequisites must be met. To install Docker, you need to have any version 64 of Ubuntu.

Yakkety 16.10 xenial 16.04 [LTS] Trusty 14.04 [LTS]

View the current version with the following command.


sudo lsb_release -a

Extra recommended bag


$ sudo apt-get update 
$ sudo apt-get upgrade 
$ sudo apt-get install curl \
linux-image-extra-$(uname -r) \
linux-image-extra-virtual

The first command is used to get the most recent package list information, the second is used to make an upgrade, and the third is used to install the aufs storage drive for Docker.

PS:

At some point, some of the Linux mirror variants tend to slim down by removing unusual modules (drives), in which case the linux-image-extra package simply contains all the "extra" kernel modules that have been omitted. This only happens in the -virtual mirror; The most common hypervisor (Virtualbox, VMWare, Xen, KVM) emulates a well-defined and constrained set of hardware, so remove unnecessary drivers to reduce the size of kernel/initrd. You can always get them by installing the extras package. uname is used to get information about the current operating system, and uname-r is used to get the version number of the current kernel.

Install Docker

Most users set up and install Docker repositories for easy upgrades. (recommended method) Some users download the DEB package and manually install and upgrade it. Some users rely on the version of Docker that accompanies their operating system, which may be out of date. These users should consult their operating system documentation and not follow these steps.

Use the warehouse for installation

You need to set up the Docker repository before you install it for the first time on a new machine. After that, you can install, update, or downgrade Docker from the repository.

Set up the warehouse

1. Install the software package to enable apt to use the repository based on HTTPS:


$ sudo apt-get install apt-transport-https \
ca-certificates

2. Add Docker's official GPG public key:


$ curl -fsSL https://yum.dockerproject.org/gpg | sudo apt-key add -

apt-key add < file > The public key command is used to add the public key to the specified file, - corresponding to standard input.

3. Verify the public key ID: 58118 E89F3A912897C070ADBF76221572C52609D.


$ apt-key fingerprint 58118E89F3A912897C070ADBF76221572C52609D

 pub  4096R/2C52609D 2015-07-14
    Key fingerprint = 5811 8E89 F3A9 1289 7C07 0ADB F762 2157 2C52 609D
 uid         Docker Release Tool (releasedocker) <docker@docker.com>t

4. Use the following command to set up the stable warehouse or to activate the test warehouse by adding testing after main on the last line.


$ sudo add-apt-repository \
    "deb https://apt.dockerproject.org/repo/ \
    ubuntu-$(lsb_release -cs) \
    main"

To disable testing warehouse, you need to edit/etc/apt/sources list, and remove the words on the corresponding line testing can.

The add-apt-repository command (essentially an Python script) adds the ppa source to source.list (and completes the import of key).

Install Docker

1. Update apt package index:


sudo apt-get update

2. Installing the latest version of Docker will replace any existing Docker.


$ sudo apt-get -y install docker-engine

Note: if you have stable and unstable repositories enabled, installing or updating without specifying a version in the apt-get install or apt-get update commands will always install the highest possible version, which is almost certainly an unstable version.

3. In a production environment, you should install the specified version instead of the latest version. Enter below to list all available versions.


$ apt-cache madison docker-engine

docker-engine | 1.13.0-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.3-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.2-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
docker-engine | 1.12.1-0~xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

4. Install the specified version:


$ sudo apt-get -y install docker-engine=<VERSION_STRING>

The Docker daemon will start automatically.

5. Run the hello-world image to verify that Docker has been installed correctly.


$ sudo apt-get update 
$ sudo apt-get upgrade 
$ sudo apt-get install curl \
linux-image-extra-$(uname -r) \
linux-image-extra-virtual
0

This command downloads a test image, runs it in the container, and when the container runs, it prints out some message information.

Docker is up and running, you need to run Docker using sudo command.

Upgrade Docker

To upgrade Docker, first run sudo apt-get upgrade, then follow the installation instructions and select the latest version you want to install.

Install from the installation package

If you don't use the Docker repository for installation, you can download the.deb package and install it manually. Every time you upgrade Docker, you will need to download a new file.

1. Download the specific ubuntu Docker version specified in the system, access to the address: https: / / apt dockerproject. org/repo/pool/main/d/docker - engine

2. Install deb package of docker:


$ sudo apt-get update 
$ sudo apt-get upgrade 
$ sudo apt-get install curl \
linux-image-extra-$(uname -r) \
linux-image-extra-virtual
1

Upgrade Docker

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

Uninstall Docker

1. Uninstall the Docker package:


$ sudo apt-get update 
$ sudo apt-get upgrade 
$ sudo apt-get install curl \
linux-image-extra-$(uname -r) \
linux-image-extra-virtual
2

2. The image, container, volume, or custom configuration file on your host will not be automatically deleted. You need to manually delete it.


$ sudo rm -rf /var/lib/docker

Related articles: