ubuntu怎么安装docker

发布时间:2022-10-27 09:42:36 作者:iii
来源:亿速云 阅读:102

本篇内容介绍了“ubuntu怎么安装docker”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

零:卸载旧版本

docker 的旧版本被称为 docker,docker.io 或 docker-engine 。如果已安装,请卸载它们:

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

当前称为 docker engine-community 软件包 docker-ce 。

一:设置仓库

在新主机上首次安装 docker engine-community 之前,需要设置 docker 仓库。之后,您可以从仓库安装和更新 docker 。

更新 apt 包索引。

$ sudo apt-get update

安装 apt 依赖包,用于通过https来获取仓库:

$ sudo apt-get install \
 apt-transport-https \
 ca-certificates \
 curl \
 gnupg-agent \
 software-properties-common

添加 docker 的官方 gpg 密钥:

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

9dc8 5822 9fc7 dd38 854a e2d8 8d81 803c 0ebf cd88 通过搜索指纹的后8个字符,验证您现在是否拥有带有指纹的密钥。

$ sudo apt-key fingerprint 0ebfcd88
 
pub rsa4096 2017-02-22 [scea]
  9dc8 5822 9fc7 dd38 854a e2d8 8d81 803c 0ebf cd88
uid   [ unknown] docker release (ce deb) <docker@docker.com>
sub rsa4096 2017-02-22 [s]

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

注意:目前 20.04 还没有国内 docker 源,暂时用 18.04 版本。

$ sudo add-apt-repository \
 "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
 bionic \
 stable"

二:安装 docker engine-community

更新 apt 包索引。

$ sudo apt-get update

安装最新版本的 docker engine-community 和 containerd

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

三:测试

输入

$ sudo docker run hello-world

如果docker和你问好——或者说出现类似以下输出

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/

就说明安装完事了。

四:免sudo运行&镜像加速

免sudo

参考如下方法将用户添加到docke组

$ sudo usermod -ag docker [你的用户名]

重启docker

$ sudo systemctl restart docker

(然而我的机器上发生了很诡异的事——我重启docker服务后依然不能以普通用户启动docker。重启机器后才能免sudo运行。)

docker镜像加速

我用了阿里云的免费加速

“ubuntu怎么安装docker”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. ubuntu下docker安装prometheus
  2. Docker容器管理--ubuntu安装docker

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ubuntu docker

上一篇:Ubuntu如何修改ip地址

下一篇:es6的class有什么用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》