在ubuntu server中安装和配置docker
经过一段时间针对不同版本的学习,现在总结当前最新的安装配置过程(应该也是比较简单的)
如果不清楚什么是docker,请参考 https://www.docker.com/
准备工作
建议在安装之前运行下面的命令对ubuntu server进行更新
sudo apt-get update
sudo apt-get upgrade
安装docker
其实应该只要一句指令即可
wget –qO- https://get.docker.com/ | sh
请注意,这里的-q后面跟的是大写的O字母
按理说是可以通过apt-get install docker.io这样的方式来安装的,但可能不是最新的,所以最保险的方式就是用上面的命令
安装成功后,会显示出来下面的输出结果
验证docker安装
通过docker version 检查版本,你可能会遇到下面的提示
这是因为当前用户的权限方面的问题,可以将当前用户加入docker这个group
sudo gpasswd –a ${USER} docker
例如下面这样
chenxizhang@ubuntu:~$ sudo gpasswd -a ${USER} docker Adding user chenxizhang to group docker
然后重新启动docker 服务
chenxizhang@ubuntu:~$ sudo service docker restart docker stop/waiting docker start/running, process 10014
再次运行docker version,你可能还是会遇到刚才同样的错误
chenxizhang@ubuntu:~$ docker version
Client:
Version: 1.8.2
API version: 1.20
Go version: go1.4.2
Git commit: 0a8c2e3
Built: Wed Oct 7 17:48:28 UTC 2015
OS/Arch: linux/amd64
Get http:///var/run/docker.sock/v1.20/version: dial unix /var/run/docker.sock: permission denied.
* Are you trying to connect to a TLS-enabled daemon without TLS?
* Is your docker daemon up and running?
这时,你需要做的是重新启动服务器
sudo reboot
再次登陆的时候,就可以正常显示版本信息,表示一切都正常了
chenxizhang@ubuntu:~$ docker version Client: Version: 1.8.2 API version: 1.20 Go version: go1.4.2 Git commit: 0a8c2e3 Built: Wed Oct 7 17:48:28 UTC 2015 OS/Arch: linux/amd64 Server: Version: 1.8.2 API version: 1.20 Go version: go1.4.2 Git commit: 0a8c2e3 Built: Wed Oct 7 17:48:28 UTC 2015 OS/Arch: linux/amd64
享受docker吧
chenxizhang@ubuntu:~$ docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 535020c3e8ad: Pull complete af340544ed62: Pull complete Digest: sha256:a68868bfe696c00866942e8f5ca39e3e31b79c1e50feaee4ce5e28df2f051d5c 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/