您现在的位置是:首页 > 文章详情

最简单的教程:在Ubuntu操作系统里安装Docker

日期:2018-10-01点击:317

Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。

今天这篇文章咱们就来将Docker安装到Ubuntu上。

1. 由于Ubuntu里apt官方库里的docker版本可能比较低,因此先用下面的命令行卸载旧版本(如果有的话)

sudo apt-get remove docker docker-engine docker-ce docker.io

2. 更新apt包索引:

sudo apt-get update

3. 执行下列命令行,使apt可以通过HTTPS协议去使用存储库:

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

4. 添加Docker官方提供的GPG密钥:

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

什么是GPG密钥呢?大家可以从阮一峰老师的博客:GPG入门教程里获得答案:

1991年,程序员Phil Zimmermann为了避开政府监视,开发了加密软件PGP。这个软件非常好用,迅速流传开来,成了许多程序员的必备工具。但是,它是商业软件,不能自由使用。所以,自由软件基金会决定,开发一个PGP的替代品,取名为GnuPG。这就是GPG的由来。

上面的文字出自阮一峰老师的博客链接:http://www.ruanyifeng.com/blog/2013/07/gpg.html

5. 设置stable存储库:

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

最后再次更新apt包索引:

6. 安装最新版本的docker-ce:

sudo apt-get install -y docker-ce

安装完毕后,可以看到Docker服务已经从/lib/systemd/system/docker.service启动了,dockerd进程id为4921:

命令行ps -aux查看进程id为4921的进程路径:/usr/bin/dockerd -H fd://

使用命令sudo docker version可以查看安装docker的版本:

使用命令sudo docker run hello-world,能观察到从远程下载这个测试用的容器:Pulling from library/hello-world:

然后看到打印消息:Hello from Docker! 说明Docker安装成功。

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/engine/userguide/

要获取更多Jerry的原创技术文章,请关注公众号"汪子熙"或者扫描下面二维码:

原文链接:https://yq.aliyun.com/articles/647277
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章