在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這樣的方式來安裝的,但可能不是最新的,所以最保險的方式就是用上面的命令

安裝成功后,會顯示出來下面的輸出結果

image

 

驗證docker安裝

通過docker version 檢查版本,你可能會遇到下面的提示

image

這是因為當前用戶的權限方面的問題,可以將當前用戶加入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/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM