当前位置: 首页 > news >正文

云服务器Linux安装Docker

系统要求

Docker 官方建议将 Docker 运行在 Linux系统上,当然也可以在其他平台运行,本篇博客只介绍在 Linux 系统上的安装方法。

Docker 运行在 CentOS7.X 版本以上,本文使用阿里云 ECS 云服务器 CentOS 7.4 版本。

Docker 需要安装在 64 位平台。

Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的 CentOS 版本是否支持 Docker。

通过 uname -r 命令查看你当前的内核版本 $ uname -r

root权限更新yum包

Linux 命令不熟悉的同学本文建议使用 root 权限登陆安装 Docker,省去很多不必要麻烦

yum update

卸载旧版本

列出安装过的 Docker 包:

yum list installed | grep docker

旧版名称是 Docker,最新社区版 docker-engine, 目前已改名为docker-ce

yum -y remove docker docker-common docker-selinux docker-engine

设置yum源

本文以 yum 安装为例子进行安装安装 yum-utils,使用 yum-config-manager 工具设置 yum 源,后面两个是 devicemapper 驱动依赖

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

使用阿里源访问

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

出现以下内容则表示成功

Loaded plugins: fastestmirror
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

查看所有仓库中docker版本

选择特定版本安装,此处我们查看社区版 docker-ce。

yum list docker-ce --showduplicates | sort -r

Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
docker-ce.x86_64            3:18.09.6-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.2-3.el7                     docker-ce-stable
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.3.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.2.ce-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
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.3.ce-1.el7                    docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
Available Packages

安装docker

此处安装社区版。

yum install docker-ce (这样写默认安装最新版本)
yum install  docker-ce-<VERSION_STRING> (指定安装版本) 
例: yum install docker-ce-18.03.1.ce

安装成功提示信息如下:

Installed:
  docker-ce.x86_64 3:18.09.6-3.el7                                                                                                 

Dependency Installed:
  container-selinux.noarch 2:2.95-2.el7_6                                                                                          

Complete!

启动并加入开机启动

systemctl start docker     启动  
systemctl restart docker   重启
systemctl enable docker    开机启动

执行 docker version 查看 Docker 版本号。

Client:
 Version:           18.09.6
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        481bc77156
 Built:             Sat May  4 02:34:58 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.6
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.8
  Git commit:       481bc77
  Built:            Sat May  4 02:02:43 2019
  OS/Arch:          linux/amd64
  Experimental:     false

验证是否安装成功

执行命令:docker run hello-world 测试是否安装成功。

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 已经安装成功了 。

接下来我们就可以访问并下载你所需要的镜像,或者使用 dockerfile 自行构建 Docker 镜像,部署安装你的应用程序到 Docker 容器中了。

配置可用镜像

注意,现在 Docker 拉取镜像被限制了,我们需要额外执行以下逻辑:

# 创建目录
sudo mkdir -p /etc/docker

# 写入配置文件
sudo tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": [
    	"https://docker.unsee.tech",
        "https://dockerpull.org",
        "https://docker.1panel.live",
        "https://dockerhub.icu"
    ]
}
EOF

# 重启docker服务
sudo systemctl daemon-reload && sudo systemctl restart docker

相关文章:

  • ElasticSearch 分词器介绍及测试:Standard(标准分词器)、English(英文分词器)、Chinese(中文分词器)、IK(IK 分词器)
  • Compounding Geometric Operations for Knowledge Graph Completion(论文笔记)
  • 深度学习驱动的智能化革命:从技术突破到行业实践
  • 深入剖析 ConcurrentHashMap:高并发场景下的高效哈希表
  • C++————类和对象(一)
  • PyQt组件间的通信方式
  • CSS—属性继承与预处理器:2分钟掌握预处理器
  • 【HeadFirst系列之HeadFirstJava】第13天之深入学习 Java GUI 编程 —— 使用 Swing 开发桌面应用
  • VS大型CPP项目调试,Debug模式,Release模式,附加到进程模式
  • 无感方波开环强拖总结
  • 基于SSM+Vue+uniapp的驾校预约管理小程序+LW示例
  • LeetCode 热题 100_字符串解码(71_394_中等_C++)(栈)
  • 蓝桥杯备赛:炮弹
  • 关于树的遍历和题目
  • 考研英语语法全攻略:从基础到长难句剖析​
  • Java数据结构第十八期:探索优先级队列的魅力(二)
  • Kubernetes滚动更新实践
  • SpringBoot 配置 Servlet/Filter/Listener
  • 【TI】如何更改 CCS20.1.0 的 WORKSPACE 默认路径
  • 慕慕手记项目日志 项目从开发到部署多环境配置 2025-3-8
  • 电商网站开发重难点/seo优化网站推广专员招聘
  • phpmyadmin wordpress/seo排名优化推广教程
  • 北京南站核酸检测点/西安专业网络推广公司
  • php 开源的企业网站/查网站流量的网址
  • 投资网站模板/苏州百度快照优化排名
  • 网站PC关键词怎么做/所有代刷平台推广