📒
notebook
  • Notebook
  • DevOps
    • Git
      • 常见 Git 操作
      • 使用 SSH 连接 Git 远程仓库
      • 使用 GPG Keys 签名 Git 提交
      • Git on macOS
    • Docker
      • macOS 安装配置 Docker
      • CentOS7 安装配置 Docker CE
  • Linux
    • CentOS
      • CentOS7 安装配置 vsftpd
      • CentOS7 设置虚拟内存
      • CentOS7 使用 acme.sh 自动申请免费 SSL 证书
      • CentOS7 修改 SSH 端口号
      • CentOS7 主机初始设置
      • 阿里云 CentOS 主机常见设置
      • CentOS7 安装配置 SS
    • nginx
      • nginx 配置 301 永久重定向
      • nginx 使用 SSL证书配置 HTTPS
      • CentOS7 安装配置 nginx
      • nginx 配置 gzip 压缩
      • nginx 代理静态网页
  • Server
    • Ghost
      • macOS 安装配置 Ghost
      • CentOS7 安装配置 Ghost
    • npm & Yarn
      • Yarn 常用命令
      • CentOS7 安装卸载升级 Yarn
      • npm & Yarn 常见错误处理
      • macOS 安装卸载升级 Yarn
    • Node.js
      • Awesome Node.js
      • CentOS7 安装卸载升级 Node.js
      • macOS 安装卸载升级 Node.js
  • Web
    • Ionic
      • 创建 Ionic & Angular 项目
      • 使用 Ionic & Cordova 构建 Android 应用
      • macOS 搭建 Ionic & Cordova 开发环境
    • CSS
      • CSS 排版技巧
      • Awesome CSS
      • CSS 三栏自适应布局
    • Angular
      • Awesome Angular
      • 创建 Angular 项目
    • HTML
      • HTML head 常用标签
      • HTML 常用 DTD 声明
      • 常用网页语义结构
    • Web 技术标准
    • JavaScript
      • Awesome JavaScript
      • JavaScript 的 eval() 函数详解
  • Mobile
    • H5
      • iOS Safari Web App 配置
  • Development Environment
    • Development Utilities
      • Awesome Windows
      • macOS 安装配置 Homebrew
      • Awesome macOS
      • macOS 安装配置 iTerm2
    • FEED
      • 常用 Gulp 插件
  • Network
    • 常见公共 DNS
  • Technology Stacks for Web Front-End Development
Powered by GitBook
On this page
  • 安装 Docker CE
  • 启动 Docker CE
  • 设置用户组
  • 运行测试
  • 镜像加速器
  • 参考文献

Was this helpful?

  1. DevOps
  2. Docker

CentOS7 安装配置 Docker CE

安装 Docker CE

使用 yum 安装依赖软件:

sudo yum -y install yum-utils device-mapper-persistent-data lvm2

添加 yum 软件源:

# 使用官方源
sudo yum-config-manager \
  --add-repo \
  https://download.docker.com/linux/centos/docker-ce.repo

# 使用中科大镜像源
sudo yum-config-manager \
  --add-repo \
  https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo

# 使用阿里云镜像源
sudo yum-config-manager \
  --add-repo \
  http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

重建 yum 缓存:

sudo yum makecache fast

安装 Docker CE:

sudo yum -y install docker-ce docker-ce-cli containerd.io

启动 Docker CE

设置开机启动:

sudo systemctl enable docker

启动 Docker CE:

sudo systemctl start docker

设置用户组

如果使用非 root 用户运行 Docker CE,需要将该用户加入 docker 用户组。

创建 docker 用户组:

sudo groupadd docker

添加当前用户到 docker 用户组:

sudo usermod -aG docker $USER

运行测试

退出当前终端工具,重新登录,并运行 hello-world :

docker run hello-world

Hello from Docker! This message shows that your installation appears to be working correctly.

......

查看所有的 container:

docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b897fbbdeccd hello-world "/hello" 5 minutes ago Exited (0) 5 minutes ago loving_bassi

删除运行测试生成的 container:

docker rm b897fbbdeccd

Tips: b897fbbdeccd 为上面查看到的 CONTAINER ID 。

删除运行测试使用的 image:

docker rmi hello-world

镜像加速器

如果是在国内主机使用 Docker,可根据需要添加第三方提供的镜像加速地址:

修改(新建)配置文件:

sudo vim /etc/docker/daemon.json

按照 JSON 格式,插入以下配置:

{
  "registry-mirrors": [
    "https://reg-mirror.qiniu.com",
    "https://dockerhub.azk8s.cn",
    "http://f1361db2.m.daocloud.io"
  ]
}

保存退出,并重启 Docker CE:

sudo systemctl daemon-reload
sudo systemctl restart docker

参考文献

PreviousmacOS 安装配置 DockerNextLinux

Last updated 4 years ago

Was this helpful?

: https://reg-mirror.qiniu.com

: https://dockerhub.azk8s.cn

: http://f1361db2.m.daocloud.io

:登录阿里云后获取

七牛云
Azure China
DaoCloud
阿里云
Get Docker Engine - Community for CentOS
Docker —— 从入门到实践