新聞中心
如何在ubuntu 14.04上安裝Docker并運行image

一. 環(huán)境確認(rèn)和準(zhǔn)備
1. 所要安裝的正是Trusty 14.40 (LTS), 硬件是x86_64的。
目前僅支持以下3個64 bit的Ubuntu 版本,支持x86_64 和armhf (ARM)硬件架構(gòu)。
- Yakkety 16.10
- Xenial 16.04 (LTS)
- Trusty 14.04 (LTS)
2. . 刪掉先前安裝過的舊版docker(新版的名字有變化) sudo apt-get remove docker docker-engine /// 新的版本中,社區(qū)版的叫docker-ce, 企業(yè)版的叫docker-ee 二. 開始安裝 1. 安裝linux-image-extra-* 以便docker能使用aufs存儲驅(qū)動 sudo apt-get update sudo apt-get install linux-image-extra-(uname -r) linux-image-extra-virtual 2. 安裝docker 有兩種安裝方式,一種是通過docker repository(docker 倉庫在線安裝),另一種是下載安裝包離線安裝。 兩種方式都試了,但在線方式一直卡住不動,只好用了離線方式。兩種安裝方式分別如下: 2.1 在線安裝 a. 安裝apt通過https訪問所需要的包
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
b. 安裝docker的官方GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | duso apt-key add -
并用下面命令確認(rèn)新安裝KEY的指紋是9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
sudo apt-key fingerprint 0EBFCD88
結(jié)果如下:
pub 4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb)
sub 4096R/F273FCD8 2017-02-22
c. 安裝docker repository 到apt source
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" // 如果是ARM架構(gòu),arch=armhf, $(lsb_release -cs) 主要是列出當(dāng)前ubuntu disctibution名字
sudo apt-get update
備注: 如果sudo add-apt-repository 或update 沒執(zhí)行成功,手工把這行加到/etc/apt/source.list中也可
deb [arch=amd64] https://download.docker.com/linux/ubuntu trusty stable
d. 開始安裝
sudo apt-get install docker-ce
2.2 離線下載
到https://download.docker.com/linux/ubuntu/dists/trusty/pool/stable/amd64/ 下載下面的 .deb安裝包,ubuntu 14.40對應(yīng)的是trusty,不同版本要到對應(yīng)目錄中下,速度不快
sudo dpkg -i path_to_package.deb
三. 運行確認(rèn)安裝已OK
sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b04784fba78d: Pull complete
Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
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 ID:
https://cloud.docker.com/
For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
ps -ef | grep docker 也能看到已運行的dockerd和docker-containerd.
+ 2003 4225 0 15:16 pts/31 00:00:00 grep --color=auto docker
root 31976 1 0 14:17 ? 00:00:04 /usr/bin/dockerd --raw-logs
root 31989 31976 0 14:17 ? 00:00:02 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc
下來就可以pull 遠程的image 跑真正的項目了 $ sudo docker docker_dev.sh ......
四. 常用操作命令
docker images // list imges
docker ps -a // list the containers running
docker pull // download image from repository
docker commit // create image
docker rm // delete container
docker rmi // delete images
docker run // run image/command in a new container
docker logs xxx (xxx 為docker images 列出的image id) // view the logs of running image
i.e. running ubuntu:14.04 image
sudo docker run -i -t ubuntu /bin/bash or
sudo docker pull ubuntu:14.04
sudo docker images
docker run -i -t ubuntu:14.04 // terminal 提示符將顯示所進入docker的HOSTNAME
do any change in this image but exit without save, enter again, nothing changed.
docker commit xxx ubuntu:14.04 // xxx 為image id, ubuntu:14.4 為image name, 也可改為其它名字便于區(qū)分,rocker images時會顯示新的名字
五. 備注:
1. 不想每次運行時都帶著sudo,那就創(chuàng)建個docker給并把當(dāng)前用戶加進去
sudo groupadd docker && sudo usermod -aG docker $USER
退出shell 再登錄就可以不用sudo了 docker run hello-world
分享題目:如何在Ubuntu14.04上安裝Docker并運行image
瀏覽地址:http://fisionsoft.com.cn/article/dpspsgo.html


咨詢
建站咨詢
