当前位置:主页 > 查看内容

Docker学习系列

发布时间:2021-06-15 00:00| 位朋友查看

简介:Docker简介与安装 Docker简介 Docker的安装 卸载旧版本 使用脚本安装 启动Docker 测试Docker是否安装 出现问题的解决方法 1 问题描述 2 原因分析 3 解决方法 4 检查是否更新成功 References Docker简介 Docker 使用 Google 公司推出的 Go 语言 (opens new wi……

Docker简介

Docker 使用 Google 公司推出的 Go 语言 (opens new window)进行开发实现,基于 Linux 内核的 cgroup (opens new window),namespace (opens new window),以及 OverlayFS (opens new window)类的 Union FS (opens new window)等技术,对进程进行封装隔离,属于 操作系统层面的虚拟化技术 (opens new window)。由于隔离的进程独立于宿主和其它的隔离的进程,因此也称其为容器。
Alt

runc是一个linux命令运行工具,用于根据OCI容器运行时规范(opens new windows)创建和运行容器

containerd是一个守护程序,管理容器生命周期

Docker 在容器的基础上,进行了进一步的封装,从文件系统、网络互联到进程隔离等等,极大的简化了容器的创建和维护。使得 Docker 技术比虚拟机技术更为轻便、快捷。
Alt

Docker的安装

Docker 可以安装在 64 位的 x86 平台或 ARM 平台上。Ubuntu 发行版中,LTS(Long-Term-Support)长期支持版本,会获得 5 年的升级维护支持,这样的版本会更稳定,因此在生产环境中推荐使用 LTS 版本。此次运行的操作系统是ubuntu 20.04

卸载旧版本

旧版本的 Docker 称为docker或者docker-engine,使用以下命令卸载旧版本:

 $ sudo apt-get remove docker \
              docker-engine \
              docker.io

使用脚本安装

在测试或开发环境中 Docker 官方为了简化安装流程,提供了一套便捷的安装脚本,Ubuntu 系统上可以使用这套脚本安装,另外可以通过--mirror选项使用国内源进行安装:

若你想安装测试版的 Docker, 请从 test.docker.com 获取脚本

# $ curl -fsSL test.docker.com -o get-docker.sh
$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun
# $ sudo sh get-docker.sh --mirror AzureChinaCloud

执行这个命令后,脚本就会自动的将一切准备工作做好,并且把 Docker 的稳定(stable)版本安装在系统中。

启动Docker

$ sudo systemctl enable docker
$ sudo systemctl start docker

测试Docker是否安装

$ docker run --rm hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
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/

若能正常输出以上信息,则说明安装成功。

出现问题的解决方法

1 问题描述

在终端执行"docker version"命令,出现如下报错:

“Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.26/images/json: dial unix /var/run/docker.sock: connect: permission denied”

2 原因分析

docker进程使用 Unix Socket 而不是 TCP 端口。而默认情况下,Unix socket 属于 root 用户,因此需要 root权限 才能访问。

3 解决方法

sudo groupadd docker          #添加docker用户组
sudo gpasswd -a $XXX docker   #检测当前用户是否已经在docker用户组中,其中XXX为用户名,例如我的,liangll
sudo gpasswd -a $USER docker  #将当前用户添加至docker用户组
newgrp docker                 #更新docker用户组

4 检查是否更新成功

再次执行"docker version"命令,发现不再出现"Got permission denied"权限报错
在这里插入图片描述

References

感谢datawhale的资料datawhale的Docker

;原文链接:https://blog.csdn.net/qq_45352802/article/details/115589426
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!
上一篇:【Linux 2】常用指令 下一篇:进程

推荐图文


随机推荐