本文翻譯自docker官網(wǎng):https://docs.docker.com/engine/install/centos/
Install Docker Engine on CentOS
To get started with Docker Engine on CentOS, make sure you
meet the prerequisites, then
install Docker.
要開(kāi)始在CentOS上使用Docker引擎藤肢,請(qǐng)確保滿足先決條件扭屁,然后安裝Docker规揪。
Prerequisites
OS requirements
To install Docker Engine, you need a maintained version of CentOS 7 or 8.
Archived versions aren't supported or tested.
若要安裝Docker引擎, 你需要CentOS 7或8的維護(hù)版本。 不支持或測(cè)試存檔版本适秩。
The centos-extras
repository must be enabled. This repository is enabled by
default, but if you have disabled it, you need to
re-enable it
必須啟用
centos-extras
存儲(chǔ)庫(kù)巍佑。默認(rèn)情情況下,此存儲(chǔ)庫(kù)處于開(kāi)啟狀態(tài)孔飒,但如果你已禁用它灌闺,你需要重新啟用它。
The overlay2
storage driver is recommended.
建議使用
overlay2
存儲(chǔ)驅(qū)動(dòng)程序坏瞄。
Uninstall old versions
Older versions of Docker were called docker
or docker-engine
. If these are
installed, uninstall them, along with associated dependencies.
舊版本的docker稱為
docker
或docker-engine
桂对。如果安裝了這些,請(qǐng)卸載它們以及相關(guān)依賴項(xiàng)鸠匀。
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
It's OK if yum
reports that none of these packages are installed.
如果
yum
報(bào)告沒(méi)有安裝這些包就OK了蕉斜。
The contents of /var/lib/docker/
, including images, containers, volumes, and
networks, are preserved. The Docker Engine package is now called docker-ce
.
/var/lib/docker/
的內(nèi)容(包括鏡像、容器缀棍、卷宅此、網(wǎng)絡(luò))將被保留。Docker引擎包現(xiàn)在成為docker-ce
Installation methods
You can install Docker Engine in different ways, depending on your needs:
你可以根據(jù)需要以不同的方式安裝Docker Engine:
-
Most users
set up Docker’s repositories and install
from them, for ease of installation and upgrade tasks. This is the
recommended approach.大多數(shù)用戶設(shè)置Docker的repositories并從中安裝睦柴,以便安裝和升級(jí)任務(wù)诽凌。這是推薦的方法。
-
Some users download the RPM 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.有些用戶下載RPM包并手動(dòng)安裝坦敌,完全手動(dòng)管理升級(jí)侣诵。這在一些情況下很有用,比如在沒(méi)有互聯(lián)網(wǎng)接入的air-gapped(氣隙)系統(tǒng)上安裝Docker狱窘。
-
In testing and development environments, some users choose to use automated
convenience scripts to install Docker.在測(cè)試和開(kāi)發(fā)環(huán)境中杜顺,一些用戶選擇使用自動(dòng)化的便利腳本來(lái)安裝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.
在一臺(tái)新的主機(jī)上首次安裝Docker Engine之前蘸炸,你需要設(shè)置Docker的repository躬络。然后,你可以從該repository安裝和更新Docker搭儒。
Set up the repository
Install the yum-utils
package (which provides the yum-config-manager
utility) and set up the stable repository.
安裝
yum-utils
包(它提供了yum config manager實(shí)用程序)并且設(shè)置穩(wěn)定的repository穷当。
$ sudo yum install -y yum-utils
$ sudo yum-config-manager \
--add-repo \
{{ download-url-base }}/docker-ce.repo
Install Docker Engine
-
Install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:
安裝最新版本的Docker Engine和contianerd提茁,或者轉(zhuǎn)至下一步安裝特定版本的:
$ sudo yum install docker-ce docker-ce-cli containerd.io
If prompted to accept the GPG key, verify that the fingerprint matches
060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
, and if so, accept it.如果提示接受GPG秘鑰,驗(yàn)證指紋是否與
060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
相匹配馁菜,如果匹配茴扁,接受它。Docker is installed but not started. The
docker
group is created, but no users are added to the group.Docker已經(jīng)安裝但是并沒(méi)有啟動(dòng)汪疮。
docker
組已經(jīng)創(chuàng)建峭火,但是沒(méi)有用戶加到該組。 -
To install a specific version of Docker Engine, list the available versions
in the repo, then select and install:要安裝特定版本的Docker Engine智嚷,在repo中列出所有可用版本卖丸,然后選擇并安裝:
a. List and sort the versions available in your repo. This example sorts
results by version number, highest to lowest, and is truncated:列出并排序repo中可用的版本。此例子通過(guò)版本號(hào)排序結(jié)果盏道,從高到底稍浆,并被截?cái)啵?/p>
$ yum list docker-ce --showduplicates | sort -r docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
The list returned depends on which repositories are enabled, and is specific
to your version of CentOS (indicated by the.el7
suffix in this example).返回列表取決于你啟用了哪些repositories,并且特定于你的CentOS版本(在本例中以.el7后綴表示)
b. Install a specific version by its fully qualified package name, which is
the package name (docker-ce
) plus the version string (2nd column)
starting at the first colon (:
), up to the first hyphen, separated by
a hyphen (-
). For example,docker-ce-18.09.1
.按其完全限定的軟件包名稱(即軟件包名稱(docker ce)加上版本字符串(第2列)摇天,從第一個(gè)冒號(hào)(:)開(kāi)始粹湃,一直到第一個(gè)連字符,用連字符(-)分隔)安裝特定版本泉坐。例如,docker-ce-18.09.1
$ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
Docker is installed but not started. The
docker
group is created, but no users are added to the group.Docker已經(jīng)安裝但是并沒(méi)有啟動(dòng)裳仆。
docker
組已經(jīng)創(chuàng)建腕让,但是沒(méi)有用戶加到該組。 -
Start Docker.
$ sudo systemctl start docker
-
Verify that Docker Engine is installed correctly by running the
hello-world
image.通過(guò)運(yùn)行
hello-world
鏡像來(lái)驗(yàn)證Docker Engine是否安裝正確歧斟。$ sudo docker run hello-world
This command downloads a test image and runs it in a container. When the
container runs, it prints an informational message and exits.該指令下載一個(gè)測(cè)試鏡像并在一個(gè)容器內(nèi)運(yùn)行它纯丸。當(dāng)容器運(yùn)行時(shí),它會(huì)打印一個(gè)信息性的消息并退出静袖。
Docker Engine is installed and running. You need 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.
Docker Engine已經(jīng)安裝完成并運(yùn)行觉鼻。 你需要使用
sudo
來(lái)運(yùn)行Docker指令。
繼續(xù)Linux post install 以允許非特權(quán)用戶運(yùn)行Docker指令和其它可選配置步驟队橙。
Upgrade Docker Engine
To upgrade Docker Engine, follow the installation instructions,
choosing the new version you want to install.
跟隨installation instructions 選擇你想要安裝的新版本來(lái)更新Docker Engine坠陈。