本节书摘来自华章出版社《循序渐进学Docker》一书中的第3章,第3.3节,作者李金榜 尹烨 刘天斯 陈纯,更多章节内容可以访问云栖社区“华章计算机”公众号查看。
3.3 在Ubuntu下安装Docker
通过GNU GRUB选择进入Ubuntu系统,配置好网络。
先通过下面命令更新一下apt软件源。
sudo apt-get update
安装Docker有两种方式。
方法一:从apt源安装docker.io,但版本比较旧。
sudo apt-get install docker.io
方法二:使用官方提供的安装脚本,可以安装最新版本的Docker,推荐使用这种安装方式,安装命令如下:
sudo apt-get install curl
curl -sSL https://get.docker.com/ | sh
安装完成后,通过如下命令启动Docker的守护进程。
$ sudo service docker start
docker start/running. process 3050
然后,可以通过如下脚本检查Docker安装是否成功。
$ sudo docker run hello-world
Unable to f?ind image 'hello-world:latest' locally
latest: Pulling from library/hello-world
03f4658f8b78: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8bc72074cc1ca36966a7
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.
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 Hub account:
https://hub.docker.com
For more examples and ideas, visit:
https://docs.docker.com/userguide/
如果不想每次运行Docker都使用sudo权限,可以把用户加到Docker组中。例如,我的用户名为harney,则添加命令如下:
$ sudo usermod -aG docker harney
重启后生效,再次执行Docker的指令,直接输入“docker ××”,不需要加“sudo”了。
现在在Ubuntu下的Docker已经安装成功了。