This website requires JavaScript.

Linux 安装 & 升级 Docker CE

by  admin  

本文主要介绍使用 Docker 安装源的方式,在 Linux 系统安装与升级 Docker CE(社区版)。


CentOS 环境安装

  1. 卸载远古版本:
$ sudo yum remove docker \
                docker-client \
                docker-client-latest \
                docker-common \
                docker-latest \
                docker-latest-logrotate \
                docker-logrotate \
                docker-engine

不是卸载旧版 Docker CE,假如已安装远古版 Docker(软件包为 docker 或者 docker-engine),需要执行卸载。

  1. 安装依赖的软件包:
$ sudo yum install -y yum-utils \
    device-mapper-persistent-data \
    lvm2
  1. 添加 yum 软件源:
$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

# 国内源:https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  1. 安装 Docker CE:
$ sudo yum install docker-ce docker-ce-cli containerd.io
  1. 设置开机启动:
$ sudo systemctl enable docker
  1. 启动 Docker CE:
$ sudo systemctl start docker

Ubuntu 环境安装

  1. 卸载远古版本:
$ sudo apt-get remove docker docker-engine docker.io containerd runc

不是卸载旧版 Docker CE,假如已安装远古版 Docker(软件包为 docker 或者 docker-engine),需要执行卸载。

  1. 安装依赖的软件包:
$ sudo apt-get update

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
  1. 添加软件源 GPG 密钥:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# 国内源:https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg
  1. 添加 apt 软件源:
$ sudo add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"

# 国内源:https://mirrors.aliyun.com/docker-ce/linux/ubuntu
  1. 更新软件源,安装 Docker CE:
$ sudo apt-get update

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

测试 Docker CE

$ sudo docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f
Status: Downloaded newer image for hello-world:latest

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 new container from 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/

升级 Docker CE

在 Linux 系统升级 Docker CE 的步骤与安装流程是一致的,安装命令同时会检测系统已存在的 Docker 软件包,然后将其升级为指定安装的 Docker 版本(默认最新版)。

相关推荐
  • 使用 TIG 构建自动化监控平台
  • Jenkins 多分支流水线构建标签
  • CentOS 7 安装 Blue Ocean
  • Certbot 申请免费 HTTPS 证书
  • SSH 免密登录 Linux 服务器