docker安裝:
第一種方式:
操作系統(tǒng)默認(rèn)的apt源有docker包,我們可以直接使用下面的apt-get命令安裝docker:
$ sudo apt-get install -y docker.io
這種方法安裝的docker在1.14.0ubuntu上,版本比較低,
第二種方式:官網(wǎng)
$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates
$ sudo apt-key adv \
--keyserver hkp://ha.pool.sks-keyservers.net:80 \
--recv-keys 58118E89F3A912897C070ADBF76221572C52609D
從官網(wǎng)上找到你Ubuntu對應(yīng)版本的Docker的Repository

然后:
$ echo "<REPO>" | sudo tee /etc/apt/sources.list.d/docker.list
把上面的 REPO 替換成你系統(tǒng)版本對應(yīng)的信息。
但是ubutun倉庫自帶的往往不是最新的;為了獲取最新的docker使用curl
再然后:
$ sudo apt-get update
#列出可用版本
$ apt-cache policy docker-engine
docker-engine:
Installed: 1.12.2-0~trusty
Candidate: 1.12.2-0~trusty
Version table:
*** 1.12.2-0~trusty 0
500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
100 /var/lib/dpkg/status
1.12.1-0~trusty 0
500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
1.12.0-0~trusty 0
500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
#最后執(zhí)行更新:
$ sudo apt-get install docker-engine
$ docker version #查看 docker版本
這種方法有可能會出現(xiàn)安裝失敗,會報(bào):
Err https://apt.dockerproject.org/repo/ ubuntu-trusty/main docker-engine amd64 1.12.6-0~ubuntu-trusty
Resolving timed out after 3513 milliseconds
E: Failed to fetch
https://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.12.6-0~ubuntu-trusty_amd64.deb
Resolving timed out after 3513 milliseconds
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
貌似是說因?yàn)榫W(wǎng)速不行,然后給停掉了,這樣的話可以找一個(gè)網(wǎng)速可以的機(jī)器把deb包下下來。(從上面報(bào)的錯(cuò)中可以找到)
https://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.12.6-0~ubuntu-trusty_amd64.deb
$ curl -O https://apt.dockerproject.org/repo/pool/main/d/docker-engine/docker-engine_1.12.6-0~ubuntu-trusty_amd64.deb
#然后通過 scp傳到服務(wù)器上
$ scp docker-engine_1.12.6-0~ubuntu-trusty_amd64.deb root@123.XXX.XXX.XXX:~
# 然后通過 dpkg安裝
$ dpkg -i docker-engine_1.12.6-0~ubuntu-trusty_amd64.deb
#可能會報(bào):
The following packages have unmet dependencies:
docker-engine : Depends: libsystemd-journal0 (>= 201) but it is not going to be installed
Recommends: aufs-tools but it is not going to be installed
Recommends: cgroupfs-mount but it is not installable or
cgroup-lite but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
#可以執(zhí)行
$ apt-get -f install
#然后在安裝
$ dpkg -i docker-engine_1.12.6-0~ubuntu-trusty_amd64.deb
第三種方式:
網(wǎng)站 https://get.docker.com 提供了curl-able的安裝腳本install.sh,我們可以通過curl的方式進(jìn)行安裝docker。
我們先安裝curl:
$ sudo apt-get update
$ sudo apt-get install curl
然后進(jìn)行docker的安裝:
$ curl -k -sSl https://get.docker.com | sudo sh
查看docker版本:
$ docker version
Client:
Version: 1.9.1
API version: 1.21
Go version: go1.4.2
Git commit: a34a1d5
Built: Fri Nov 20 13:08:59 UTC 2015
OS/Arch: linux/amd64
建議使用第二種方式;
可以通過 https://get.docker.com 查看腳本命令??梢灾佬遁d方式是
sudo apt-get remove docker-engine
docker驗(yàn)證
若上述命令執(zhí)行成功后,就要驗(yàn)證一下docker是否安裝成功了:
執(zhí)行下面命令
sudo docker run hello-world
若顯示如下信息:
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](http://lib.csdn.net/base/docker) 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 bashShare images, automate workflows, and more with a free Docker Hub account: https://hub.docker.comFor more examples and ideas,
visit: https://docs.docker.com/userguide/
證明docker正常工作!下面我們就可以開始docker之旅啦~
補(bǔ)充命令:可以使用命令查看容器狀態(tài)
1、查看正在運(yùn)行的容器
sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2、查看所有的容器
sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES5ddce0ca3e4f hello-world "/hello" 2 minutes ago Exited (0) 2 minutes ago serene_jennings551e257cbc08 hello-world "/hello" 2 minutes ago Exited (0) 2 minutes ago drunk_sammet584c3a343739 hello-world "/hello" About an hour ago Exited (0) About an hour ago trusting_hypatia005c31a4cd49 hello-world "/hello" About an hour ago Exited (0) About an hour ago goofy_easleyb865dac40a66 hello-world "/hello" About an hour ago Exited (0) About an hour ago furious_borg
3、查看本地鏡像
sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEhello-world latest 0a6ba66e537a 8 weeks ago 960 B
4、從鏡像中運(yùn)行/停止一個(gè)新實(shí)例
sudo docker run/stop --help
通過help查詢一些參數(shù),根據(jù)自己的id啟動(dòng)/停止實(shí)例
注意:
每次 使用docker命令都需要使用sudo
這里把當(dāng)前用戶加入到docker組就可以直接使用命令,而不用每次都加sudo
$ sudo groupadd docker
#改完后需要重新登陸用戶
$ sudo gpasswd -a ${USER} docker