Docker安装教程

这里介绍两种安装方法:centsOS安装和Ubuntu安装

CentOS安装

linux内核版本建议3.8以上,作者本人使用的是3.10;查看内核版本命令:uname -r

一般CentOS7以上都可以

推荐使用root用户操作,避免不必要的麻烦,反正都是个人使用,用户方面并不影响

CentOS安装Docker有两种方式:自动安装和手动安装

1、更新yum源(非必要操作,建议执行,可以避坑)

$ yum -y update

注意:

$ yum -y update:升级所有包同时也升级软件和系统内核
$ yum -y upgrade:只升级所有包,不升级软件和系统内核

2、如果已安装过docker先删除

$ yum remove docker-*

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

3、使用官方安装脚本自动安装

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

4、也可以使用国内 daocloud 一键安装命令

curl -sSL https://get.daocloud.io/docker | sh

1、更新yum源(非必要操作,建议执行,可以避坑)

$ yum -y update

注意:

$ yum -y update:升级所有包同时也升级软件和系统内核
$ yum -y upgrade:只升级所有包,不升级软件和系统内核

2、如果已安装过docker先删除

$ yum remove docker-*

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

3、设置仓库

新主机首次安装 Docker Engine-Community之前,需要设置Docker仓库,之后,可以从仓库安装和更新 Docker。

设置仓库,需要安装所需的软件包。yum-utils 提供了 yum-config-manager ,并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2,这两个是 devicemapper 必要依赖包

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

4、设置yum源

  • 官方yum源(中央仓库):由于服务器在国外比较慢,多下几次就下载下来了
$ yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  • 阿里云yum源:作者目前使用的,网上大部分教程用的也都是这个源
$ yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  • 清华大学消息来源:消息来源很多,这里有三个
    [En]

    sources of Tsinghua University: there are many sources, here are three*

$ yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

5、查看docker的可用版本

查看所有仓库中docker版本,并选择特定版本安装

个人使用推荐社区版 docker-ce,免费版本

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

6、安装docker-ce版

全称:Docker Engine-Community,社区版

  • 默认安装最新版本
$ yum install docker-ce
  • 指定安装版本
$ yum install  docker-ce-
例: yum install docker-ce-20.10.9.ce
  • 如果下面显示类似消息,则表示安装成功
    [En]

    if a similar message is displayed below, the installation is successful*

Installed:  docker-ce.x86_64 3:20.10.11-3.el7Dependency Installed:  audit-libs-python.x86_64 0:2.8.5-4.el7  checkpolicy.x86_64 0:2.5-8.el7  container-selinux.noarch 2:2.119.2-1.911c772.el7_8  containerd.io.x86_64 0:1.4.12-3.1.el7  docker-ce-cli.x86_64 1:20.10.11-3.el7  docker-ce-rootless-extras.x86_64 0:20.10.11-3.el7  docker-scan-plugin.x86_64 0:0.9.0-3.el7  fuse-overlayfs.x86_64 0:0.7.2-6.el7_8  fuse3-libs.x86_64 0:3.6.1-4.el7  libcgroup.x86_64 0:0.41-21.el7  libsemanage-python.x86_64 0:2.5-14.el7  policycoreutils-python.x86_64 0:2.5-34.el7  python-IPy.noarch 0:0.75-6.el7  setools-libs.x86_64 0:3.3.8-4.el7  slirp4netns.x86_64 0:0.4.3-4.el7_8Complete!

7、配置镜像加速

必须配置,否则会出现镜像访问不稳定、下载速度慢等问题

[En]

Must be configured, otherwise there will be problems such as unstable access to the image and slow download

执行命令:

$ mkdir -p /etc/docker
$ tee /etc/docker/daemon.json <

8、启动并加入开机启动

  • 启动docker
$ systemctl start docker
  • 重启命令
$ systemctl restart docker
  • 设置开机自启
$ systemctl enable docker
[root@VM-0-15-centos ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

  • 查看docker版本
$ docker version
[root@VM-0-15-centos ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.11
 API version:       1.41
 Go version:        go1.16.9
 Git commit:        dea9396
 Built:             Thu Nov 18 00:38:53 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.11
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.9
  Git commit:       847da18
  Built:            Thu Nov 18 00:37:17 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.12
  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Ubuntu安装

这里的安装方式和CentOS类似,就不详细赘述了

安装Docker有两种方式:自动安装和手动安装

社区版支持以下的 Ubuntu 版本:

  • Xenial 16.04 (LTS)
  • Bionic 18.04 (LTS)
  • Cosmic 18.10
  • Disco 19.04
  • 更新的版本

社区版支持Ubuntu内核: x86_64(或 amd64)armhf,arm64,s390x (IBM Z),和 ppc64le(IBM的Power)架构。

1、更新ubuntu的apt源索引

$ sudo apt-get update

2、如果已安装过docker先删除

$ sudo apt-get remove docker docker-engine docker.io containerd runc

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

3、使用官方安装脚本自动安装

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

4、也可以使用国内 daocloud 一键安装命令

curl -sSL https://get.daocloud.io/docker | sh

1、更新ubuntu的apt源索引

$ sudo apt-get update

2、如果已安装过docker先删除

$ sudo apt-get remove docker docker-engine docker.io containerd runc

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

3、安装包允许apt通过HTTPS使用仓库

$ sudo dpkg --configure -a
$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

4、添加Docker官方GPG key

这是外部服务器的地址,所以当网络出现故障时,它就会失败!网络好了,再执行几次也没问题]

[En]

This is the address of a foreign server, so when the network is bad, it will fail! When the network is good, it will be no problem to execute it a few more times]

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

5、设置Docker稳定版仓库

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

添加仓库后,更新apt源索引

$ sudo apt-get update

前面的准备工作完成以后,接下来安装最新版Docker CE(社区版)

$ sudo apt-get install docker-ce

检查Docker CE是否安装正确

$ sudo docker run hello-world

出现了 helo from Docker则表示上面的安装成功!也可以使用上面CentOS的方法来检测,就是命令方式换成Ubuntu的

6、docker的基本命令

启动docker
sudo service docker start

停止docker
sudo service docker stop

重启docker
sudo service docker restart

列出镜像
docker image ls

拉取镜像
docker image pull library/hello-world

删除镜像
docker image rm 镜像id/镜像ID

创建容器
docker run [选项参数] 镜像名 [命令]

停止已在运行的容器<details><summary>*<font color='gray'>[En]</font>*</summary>*<font color='gray'>Stop a container that is already running</font>*</details>
docker container stop 容器名或容器id

启动一个已经停止的容器
docker container start 容器名或容器id

kill掉一个已经在运行的容器
docker container kill 容器名或容器id

删除容器
docker container rm 容器名或容器id

Original: https://www.cnblogs.com/wylshkjj/p/15612519.html
Author: HashFlag
Title: Docker安装教程

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/524321/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • Android(Linux)控制GPIO方法二

    前文《Android(Linux)控制GPIO的方法及实时性分析》主要使用Linux shell命令控制GPIO,该方法可在调试过程中快速确定GPIO硬件是否有问题,即对应的GPI…

    Linux 2023年6月7日
    074
  • 常用的分布式锁和redis和zk两种分布式锁的对比

    常用的分布式锁 一、基于数据库实现分布式锁 1. 悲观锁 利用select … where … for update 排他锁 注意: 其他附加功能与实现一基…

    Linux 2023年5月28日
    076
  • Linux(进阶篇)

    一、进程 1 进程和内存管理 1.1 进程和线程的区别 线程是程序执行的最小单位,而进程是操作系统分配资源的最小单位 一个进程由一个或多个线程组成,线程是一个进程中代码的不同执行路…

    Linux 2023年6月7日
    081
  • linux 修改文件的创建时间—–touch命令

    1、首先不会用touch 可以自己man touch查看并学习,推出man按q 2、举例 给文件修改时间 touch -mt 201909052248 test.log -m mo…

    Linux 2023年6月13日
    091
  • 017 Linux 之啥是 ssh ?

    1 什么是 ssh?有什么用? (1)ssh 是一种协议 (2)ssh 服务 2 ssh 基于密匙的安全验证过程是怎样的? 3 对称加密与非对称加密区别是什么? (1)对称加密 (…

    Linux 2023年5月27日
    0109
  • 招人、找人、找大牛啦!

    招人、找人、找大牛啦! 有意从事、投资TO B业务,含新型操作系统、大数据、人工智能、高性能计算、分布式应用软件的研发、高管、合伙人朋友请联系我,我司正在启动新一轮业务拓展!详情私…

    Linux 2023年6月6日
    088
  • 《卡死你3000》批量文件复制命令详解

    卡死你3000简介: 名词解释: 批量顺序复制文件:从主控机,到从被控机1,被控机2,复制文件。有卡住问题。 批量并发复制文件:从主控机,到从被控机1,被控机2,复制文件。使用多线…

    Linux 2023年6月13日
    0115
  • Linux编译安装、压缩打包与定时任务服务

    一、编译安装 即使用源代码编译安装的方式,编译打包软件。特点: 可以自定制软件; 可以按需构建软件; 编译安装案例 1、下载源代码包(这里以Nginx软件包源代码为例) wget …

    Linux 2023年5月27日
    087
  • NAT回流(Twice NAT)Hairping 参数详解

    内网用户需要通过域名访问内网的服务器,一般商用环境是无法访问的,需要经过以下配置,原理不说了,直接说配置。 nat (inside,inside) source dynamic i…

    Linux 2023年6月6日
    098
  • 什么是草台班子?

    有个朋友最近想跳槽,他对管理的兴趣不大,而且认为自己的性格也不适合做管理,更想成为技术专家。基于这些考虑,他希望能进入知名大厂,如果面试不顺利,去小而美公司也行。他的面试经验不多,…

    Linux 2023年6月6日
    0100
  • 小记:音频格式转化ByPython(上)

    近日新买了个耳机,店家附送了一些周董的无损音乐资源,收到货后迫不及待的下载试听,才发现这些资源是wav格式的,导入播放器后歌名、作者、专辑等全是未知,当时想着是不是店家的资源有问题…

    Linux 2023年6月8日
    0103
  • redis启动失败 提示Unregistered Authentication Agent for unix-process:6176

    使用宝塔软件安装的redis 一直没启动起来。 使用 journalctl -xe 命令查看原因,发现redis.pid已经存在。 进入该目录,删除redis.pid。 再使用sy…

    Linux 2023年5月28日
    0331
  • Linux机器在命令行操作时开启/关闭代理

    命令行操作时,如果需要连接通过代理才能访问的地址,可以通过配置当前shell的配置文件来手动开启/关闭代理 注意:代理只对当前用户当前shell生效,切换用户或者重新连接需要重新开…

    Linux 2023年6月6日
    087
  • 【转】 一条 SQL 的执行过程详解

    MySQL 体系架构 – 连接池组件 1、负责与客户端的通信,是半双工模式,这就意味着某一固定时刻只能由客户端向服务器请求或者服务器向客户端发送数据,而不能同时进行。 …

    Linux 2023年6月13日
    0112
  • opencv

    404. 抱歉,您访问的资源不存在。 可能是网址有误,或者对应的内容被删除,或者处于私有状态。 代码改变世界,联系邮箱 contact@cnblogs.com 园子的商业化努力-困…

    Linux 2023年6月14日
    0102
  • 泛微 OA 前台 GetShell 复现

    自行搭建环境: 漏洞路径: /weaver/weaver.common.Ctrl/.css?arg0=com.cloudstore.api.service.Service_Chec…

    Linux 2023年5月28日
    093
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球