CentOS 安裝 Docker

本文翻譯自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.

要開始在CentOS上使用Docker引擎,請確保滿足先決條件,然后安裝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的維護版本。 不支持或測試存檔版本。

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存儲庫。默認情情況下,此存儲庫處于開啟狀態(tài),但如果你已禁用它,你需要重新啟用它。

The overlay2 storage driver is recommended.

建議使用overlay2存儲驅動程序。

Uninstall old versions

Older versions of Docker were called docker or docker-engine. If these are
installed, uninstall them, along with associated dependencies.

舊版本的docker稱為dockerdocker-engine。如果安裝了這些,請卸載它們以及相關依賴項。

$ 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報告沒有安裝這些包就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/的內容(包括鏡像、容器、卷、網(wǎng)絡)將被保留。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ù)用戶設置Docker的repositories并從中安裝,以便安裝和升級任務。這是推薦的方法。

  • 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包并手動安裝,完全手動管理升級。這在一些情況下很有用,比如在沒有互聯(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.

    在測試和開發(fā)環(huán)境中,一些用戶選擇使用自動化的便利腳本來安裝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.

在一臺新的主機上首次安裝Docker Engine之前,你需要設置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實用程序)并且設置穩(wěn)定的repository。

$ sudo yum install -y yum-utils

$ sudo yum-config-manager \
    --add-repo \
    {{ download-url-base }}/docker-ce.repo

Install Docker Engine

  1. Install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:

    安裝最新版本的Docker Engine和contianerd,或者轉至下一步安裝特定版本的:

    $ 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秘鑰,驗證指紋是否與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)安裝但是并沒有啟動。docker組已經(jīng)創(chuàng)建,但是沒有用戶加到該組。

  2. 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中可用的版本。此例子通過版本號排序結果,從高到底,并被截斷:

    $ 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列),從第一個冒號(:)開始,一直到第一個連字符,用連字符(-)分隔)安裝特定版本。例如,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)安裝但是并沒有啟動。docker組已經(jīng)創(chuàng)建,但是沒有用戶加到該組。

  3. Start Docker.

    $ sudo systemctl start docker
    
  4. Verify that Docker Engine is installed correctly by running the hello-world
    image.

    通過運行hello-world鏡像來驗證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.

    該指令下載一個測試鏡像并在一個容器內運行它。當容器運行時,它會打印一個信息性的消息并退出。

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)安裝完成并運行。 你需要使用sudo來運行Docker指令。
繼續(xù)Linux post install 以允許非特權用戶運行Docker指令和其它可選配置步驟。

Upgrade Docker Engine

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

跟隨installation instructions 選擇你想要安裝的新版本來更新Docker Engine。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容