首页 > 编程知识 正文

docker准备安装环境步骤,docker下载教程

时间:2023-05-05 01:01:15 阅读:12425 作者:2399

一、使用正式安装脚本自动安装

安装命令如下:

curl-fssl https://get.docker.com|bash-s docker---- mirroraliyun

也可以单击国内的daocloud安装命令。

curl-SSL https://get.Dao cloud.io/docker|sh

二.手动安装

1、卸载旧版本

Docker的早期版本称为Docker、docker.io或docker-engine。 如果已安装,请卸载。

$ sudo apt-getremovedockerdocker-engine docker.iocontainerdrunc

目前称为Docker Engine-Community软件包docker-ce。

安装代理程序引擎-通信。 以下介绍两种方式。

2、使用Docker仓库安装

在新主机上首次安装Docker Engine-Community之前,必须设置Docker仓库。 然后,可以从仓库安装和更新Docker。

2.1仓库设置

更新apt包索引。

$ sudo apt-get update

安装apt相关软件包以在HTTPS上检索仓库:

$ sudo apt-get installapt-transport-httpsca-certificatescurlGnuPG-agentsoftware-properties-come

添加Docker的官方GPG密钥:

$ curl-fssl https://mirrors.ustc.edu.cn/docker-ce/Linux/Ubuntu/gpg|sudo apt-keyadd -

通过搜索9dc 858229 fc7DD 38854 AE 2d 88 d 81803 c0ebfcd 88指纹的最后8个字符来确定是否有带指纹的钥匙。

$ sudo apt-key fingerprint0ebfcd 88 pub RSA 40962017-02-22 [ scea ] 9dc 858229 fc7DD 38854 AE 2d 88 d 81803 c0ebfcd 88 uid [ unknown ] DOD

使用以下命令设置稳定版仓库

$ sudo add-apt-repository' deb [ arch=amd64 ] https://mirrors.ustc.edu.cn/docker-ce/Linux/Ubuntu/$ (

3、安装代理程序引擎通信

更新apt包索引。

$ sudo apt-get update

安装最新版本的Docker Engine-Community和containerd,或执行下一步以安装特定版本。

$ sudo apt-getinstalldocker-ce docker-ce-CLI containerd.io

要安装特定版本的Docker Engine-Community,请列出仓库的可用版本并选择安装。 列出仓库中可用的版本。

$ apt-cachemadisondocker-ce docker-ce|5:18.09.1至3-0至Ubuntu-xenial|https://mirrors.ustc.edu.cn/do 5:18.09.0~3-0~Ubuntu-xenial|https://mirrors.ustc.edu.cn/docker-ce/stable amd64打包代理- ce | docker-ce/Linux/Ubuntu 18.06.0至ce至3-0至Ubuntu|https://mirrors.ustc.edu.cn/docker-ce/Linux/Ubuntu xx .

使用第二列中的版本字符串安装特定版本,例如5:18.09。

1~3-0~ubuntu-xenial。

$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

测试 Docker 是否安装成功,输入以下指令,打印出以下信息则安装成功:

$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete                                                                                                                                  Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f 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/

三、WSL2卸载

1. 删除某软件,及其安装时自动安装的所有包

sudo apt-get autoremove docker docker-ce docker-engine docker.io containerd runc

2. 删除docker其他没有没有卸载

dpkg -l | grep docker   dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P # 删除无用的相关的配置文件

3.卸载没有删除的docker相关插件(结合自己电脑的实际情况)

sudo apt-get autoremove docker-ce-*

4.删除docker的相关配置&目录

sudo rm -rf /etc/systemd/system/docker.service.d sudo rm -rf /var/lib/docker

5.确定docker卸载完毕

docker --version

四、WSL2安装

首先进入Ubuntu shell,更换Ubuntu官方源为国内源,加快下载速度。执行。

vim /etc/apt/sources.list

将内容替换为下方:

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted

deb http://mirrors.aliyun.com/ubuntu/ focal universe

deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe

deb http://mirrors.aliyun.com/ubuntu/ focal multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted

deb http://mirrors.aliyun.com/ubuntu/ focal-security universe

deb http://mirrors.aliyun.com/ubuntu/ focal-security multiverse

接下来添加Docker源:

依次执行如下命令:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" sudo apt update

配置完成软件源之后下一步是安装Docker,命令如下

sudo apt install -y docker-ce

最后一个步骤,启动Docker daemon。但是此处有一个问题,WSL2经过测试无法使用systemctl命令(此问题已经解决,参见博客末尾FAQ),因此我们使用service命令启动Docker daemon。命令如下所示:

sudo service docker start

如果有问题

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.24/images/json: dial unix /var/run/docker.sock: connect: permission denied

执行:sudo chmod a+rw /var/run/docker.sock 

或者添加用户组:

通过将用户添加到docker用户组可以将sudo去掉,命令如下 sudo groupadd docker #添加docker用户组 sudo gpasswd -a $USER docker #将登陆用户加入到docker用户组中 例如:sudo gpasswd -a twmub docker newgrp docker #更新用户组

 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。