Translated from Get Docker CE for CentOS | Docker Docs, subject to Docker official documents
Click to view my [blog original] (https://abelsu7.top/2019/01/10/install-docker-ce-on-centos7/)
centos-extras
repository. In CentOS 7 this repository is enabled by default, if it has been disabled before, you need to re-enableoverlay2
as Docker's storage driverThe package name of the old version of Docker in CentOS is docker
or docker-engine
. If you have installed an old version of Docker before, you need to uninstall the old version of Docker and related dependencies:
> sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
If yum
prompts Uninstall successful or No related package found, proceed to the next step.
Note: The contents of the /var/lib/docker/
directory, including images, containers, volume groups, networks and other files will be reserved. Docker CE's new package is named docker-ce
.
There are three ways to install Docker CE, which can be selected according to actual needs:
Before installing Docker CE for the first time, you need to create a Docker repository. After that, you can install and update Docker through the warehouse.
1.Install the required packages. yum-utils
provides yum-config-manager
tool, storage driver devicemapper
depends on device-mapper-persistent-data
and lvm2
:
> sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
stable
version of the repository:> sudo yum-config-manager \
- - add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
3.Optional: **Enable edge
and test
Warehouse. These repositories are included in the docker.repo
file, but ** are disabled by default. They can be enabled together with the stable
repository.
> sudo yum-config-manager --enable docker-ce-edge
> sudo yum-config-manager --enable docker-ce-test
Use the yum-config-manager
command with the --disable
parameter to disableedge
** or test
warehouse**, use the --enable
parameter to Re-enable. For example, the following command will disable the edge
repository:
> sudo yum-config-manager --disable docker-ce-edge
Starting from Docker
17.06
version, releases ofstable
repository will also be pushed toedge
andtest
repositories.
Click here to view **Docker official instructions onstable
andedge
.
> sudo yum install docker-ce
If prompt whether to accept the GPG key, you need to verify whether the key fingerprint meets the following content, if it does, click accept to continue the installation:
060 A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
If multiple Docker repositories are enabled and no version is specified in the
yum install
oryum update
command, Docker with the latest version number in all repositories will be installed.
> yum list docker-ce --showduplicates | sort -r
docker-ce.x86_64 18.09.0.ce-1.el7.centos docker-ce-stable
At this time, the format of the installation package name is docker-ce-<VERSION STRING>
. For example, install Docker CE of version 18.03.0
:
> sudo yum install docker-ce-18.03.0.ce
At this point Docker should have been installed, but it has not been started. New user groupdocker
has also been created and is currently empty.
3.Start Docker:
> sudo systemctl start docker
hello-world
image to verify that Docker is installed correctly:> sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:1. The Docker client contacted the Docker daemon.2. The Docker daemon pulled the "hello-world" image from the Docker Hub.(amd64)3. The Docker daemon created a newcontainerfrom that image which runs the
executable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
If you need to upgrade Docker CE, you can choose to install the latest version of docker-ce
according to the above installation tutorial to complete the upgrade.
If you cannot use the Docker repository, you can download.rpm
installation package to manually install Docker CE.
Go to https://download.docker.com/linux/centos/7/x86_64/stable/Packages/, download the RPM installation package of the corresponding version.
Use the yum
command to install the RPM package**:
> sudo yum install /path/to/package.rpm
3.Start Docker:
> sudo systemctl start docker
hello-world
image to verify that Docker is installed correctly:> sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:1. The Docker client contacted the Docker daemon.2. The Docker daemon pulled the "hello-world" image from the Docker Hub.(amd64)3. The Docker daemon created a newcontainerfrom that image which runs the
executable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
If you need to upgrade, you can download the new version of the RPM installation package and use the yum upgrade
command to upgrade:
> sudo yum -y upgrade /path/to/package.rpm
Through the one-click installation script provided by Docker, you can quickly install Docker CE in the development environment without interaction. get.docker.com and test.docker.com correspond to the edge
and test
versions respectively. Script source code is stored in docker-install repository .
Docker official It is not recommended to use the installation script in a production environment
The following example will use the script provided by get.docker.com Install the latest released version of Docker CE. If you want to install the latest test version, just replace the script with test.docker.com, and replace get
with test
in the following example command:
> curl -fsSL https://get.docker.com -o get-docker.sh
> sudo sh get-docker.sh
< output truncated>
If you need to allow nonroot
** users to use Docker**, use the following command to **add the user to **docker
user group:
> sudo usermod -aG docker your-user
Log out and log in again to take effect. After start Docker:
> sudo systemctl start docker
Run the hello-world
image to verify that Docker is installed correctly:
> sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:1. The Docker client contacted the Docker daemon.2. The Docker daemon pulled the "hello-world" image from the Docker Hub.(amd64)3. The Docker daemon created a newcontainerfrom that image which runs the
executable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
> sudo yum remote docker-ce
Mirrors, containers, volume groups and custom configuration files on the host need to be manually deleted:
> sudo rm -rf /var/lib/docker
Reference materials
Get Docker CE for CentOS | Docker Docs
Recommended Posts