Install using the rpm repository
1. Set up the repository
sudo yum install -y yum-utils
然后执行
yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo
或
yum-config-manager --add-repo http://mirrors-aliyun.com/docker-ce/linux/centos/docker-ce.repo
2. Install Docker Engine
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
3. Start Docker
sudo systemctl start docker
4. Verify that the Docker Engine installation is successful by running the hello-world image.
sudo docker run hello-world
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.
Install from a package
If you can't use Docker's rpm
repository to install Docker Engine, you can download the .rpm
file for your release and install it manually. You need to download a new file each time you want to upgrade Docker Engine.
-
Go to https://download.docker.com/linux/centos/ and choose your version of CentOS. Then browse to
x86_64/stable/Packages/
and download the.rpm
file for the Docker version you want to install. -
Install Docker Engine, changing the following path to the path where you downloaded the Docker package.
sudo yum install /path/to/package.rpm
Docker is installed but not started. The
docker
group is created, but no users are added to the group. -
Start Docker.
sudo systemctl start docker
-
Verify that the Docker Engine installation is successful by running the
hello-world
image.sudo docker run hello-world
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.
Tip
Receiving errors when trying to run without root?
The
docker
user group exists but contains no users, which is why you’re required to usesudo
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, download the newer package files and repeat the installation procedure, using yum -y upgrade
instead of yum -y install
, and point to the new files.
Install using the convenience script
Docker provides a convenience script at https://get.docker.com/ to install Docker into development environments non-interactively. The convenience script isn't recommended for production environments, but it's useful for creating a provisioning script tailored to your needs. Also refer to the install using the repository steps to learn about installation steps to install using the package repository. The source code for the script is open source, and you can find it in the docker-install
repository on GitHub.
Always examine scripts downloaded from the internet before running them locally. Before installing, make yourself familiar with potential risks and limitations of the convenience script:
- The script requires
root
orsudo
privileges to run. - The script attempts to detect your Linux distribution and version and configure your package management system for you.
- The script doesn't allow you to customize most installation parameters.
- The script installs dependencies and recommendations without asking for confirmation. This may install a large number of packages, depending on the current configuration of your host machine.
- By default, the script installs the latest stable release of Docker, containerd, and runc. When using this script to provision a machine, this may result in unexpected major version upgrades of Docker. Always test upgrades in a test environment before deploying to your production systems.
- The script isn't designed to upgrade an existing Docker installation. When using the script to update an existing installation, dependencies may not be updated to the expected version, resulting in outdated versions.