ubuntu18.04/20.04 安装docker

Posted 奇妙之二进制

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu18.04/20.04 安装docker相关的知识,希望对你有一定的参考价值。

一、更换国内软件源

打开应用程序页面—>软件和更新

在打开页面的下拉框中,选中“其他站点”,点击“选择最佳服务器”

在终端中输入以下命令

sudo apt-get update

没有错误则成功了。

二、安装需要的包

在终端输入命令

sudo apt-get install apt-transport-https ca-certificates software-properties-common curl

没有错误则成功。

三、添加 GPG 密钥,并添加 Docker-ce 软件源

官方的软件源(不推荐,很慢):

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

中国科技大学的 Docker-ce 源(其他源类似):

curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \\
$(lsb_release -cs) stable"

注意:添加错了可以用以下命令删除

#查询keyid,下图
sudo apt-key list
#keyid 就是90那一串
sudo apt-key del <keyid>
#加参数-r可以移除
sudo add-apt-repository -r "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

更新软件包缓存

sudo apt-get update

四、安装 Docker-ce

sudo apt-get install docker-ce

五、测试运行

sudo docker run hello-world

显示如下就成功了:

vic@ubuntu:~/Desktop$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:bfea6278a0a267fad2634554f4f0c6f31981eea41c553fdf5a83e95a41d40c38
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/

六、添加当前用户到 docker 用户组,可以不用 sudo 运行 docker

将当前用户添加到 docker 组

sudo gpasswd -a $USER docker

重新登录或者用以下命令切换到docker组

newgrp - docker

重启docker服务

sudo service docker restart
# 不加sudo直接执行docker命令检查效果
vic@ubuntu:~/Desktop$ docker ps -a
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
f3ea3d864c8a   hello-world   "/hello"   4 minutes ago   Exited (0) 4 minutes ago             strange_kowalevski

以上是关于ubuntu18.04/20.04 安装docker的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu 18.04/20.04 CV环境配置(中):Tensorrt + Pytorch安装配置

Ubuntu 18.04/20.04 CV环境配置(中):Tensorrt + Pytorch安装配置

Ubuntu 18.04/20.04 CV环境配置(中):Tensorrt + Pytorch安装配置

ubuntu/linux系统知识虚拟机安装ubuntu18.04/20.04

ubuntu/linux系统知识虚拟机安装ubuntu18.04/20.04

ubuntu18.04/20.04/22.04安装显卡驱动与显卡信息查询