docker 安装

Docker 概述

Docker 是一个应用程序开发、部署、运行的平台,使用 go 语言开发。相较于传统的主机虚拟化,Docker 提供了轻量级的应用隔离方案,并且为我们提供了应用程序快速扩容、缩容的能力。

Docker核心思想: 隔离

docker 实现了测试环境和上线环境统一

Docker 安装

环境准备,centos 7.5

Linux内核要求在 3.0以上

[root@localhost ~]# uname -r
3.10.0-862.el7.x86_64

安装

帮助文档(官方): https://docs.docker.com/engine/install/centos/

1. 卸载旧版本

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

2. 需要的安装包

yum install -y yum-utils

3. 设置镜像仓库

# 官网默认使用国外仓库,国内使用速度慢,不推荐
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
    
# 推荐使用阿里云仓库
yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
 # 两种选其中一个即可

4. 更新yum 源

yum clean all  # 清空yum源

yum makecache   # 创建yum源缓存

5. 安装docker

# 安装相关软件 docker-ce 社区版, # ee企业版 
yum install docker-ce docker-ce-cli containerd.io


# 可能报错  container-selinux> = 2.9  # 使用 阿里源安装container-selinux

[root@localhost~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost~]# yum install epel-release
[root@localhost~]# yum install container-selinux

6. 启动Docker

systemctl start docker		# 启动
systemctl stop docker		# 停止
systemctl restart docker	# 重启
systemctl status docker		# 状态
systemctl enable docker 	# 开启自启动

7. 验证是否安装成功

docker version		# 查看版本

8. 测试

docker run hello-world		# 运行一个hello-word 容器
--------------------------------------------------------------------------
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d
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/

# 看到以上信息表示安装成功

9. 查看镜像

[root@localhost ~]# docker images
-------------------------------------------------------------
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    bf756fb1ae65   13 months ago   13.3kB

10. 卸载 docker (了解)

#1. 卸载依赖
yum remove docker-ce docker-ce-cli containerd.io
#2. 删除资源
rm -rf /var/lib/docker
# /var/lib/docker 是docker的默认工作路径!

11. 镜像加速器

# 创建daemon.json 文件, 文件不存在vim 自动创建
vim /etc/docker/daemon.json  

{
"registry-mirrors":["加速网址"]
}
# 加速网址可以去阿里云申请

 systemctl daemon-reload		# 重新加载配置文件

 systemctl restart docker		   # 重启docker

也可以用下面的镜像加速,(来源网络)

{
"registry-mirrors":["http://hubmirror.c.163.com","https://pee6w651.mirror.aliyuncs.com","https://registry.docker-cn.com"]
}

————————————————————————————


docker 最简单的安装方式

# 一条命令安装docker 
curl -fsSL https://get.docker.com |bash -s docker --mirror Aliyun

posted @ 2021-02-08 14:03  内向是一种性格  阅读(73)  评论(0编辑  收藏  举报