2021-05-12 14:32:11
如何在Ubuntu 14.04上安裝Docker並執行image
如何在Ubuntu 14.04上安裝Docker並執行image
一. 環境確認和準備
1. 所要安裝的正是Trusty 14.40 (LTS), 硬體是x86_64的。
目前僅支援以下3個64 bit的Ubuntu 版本,支援x86_64 和armhf (ARM)硬體架構。
- Yakkety 16.10
- Xenial 16.04 (LTS)
- Trusty 14.04 (LTS)
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 -
並用下面命令確認新安裝KEY的指紋是9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
sudo apt-key fingerprint 0EBFCD88
結果如下:
pub 4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb) <docker@docker.com>
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架構,arch=armhf, $(lsb_release -cs) 主要是列出當前ubuntu disctibution名字
sudo apt-get update
備註: 如果sudo add-apt-repository 或update 沒執行成功,手工把這行加到/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對應的是trusty,不同版本要到對應目錄中下,速度不快
sudo dpkg -i path_to_package.deb
三. 執行確認安裝已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, 也可改為其它名字便於區分,rocker images時會顯示新的名字
五. 備註:
1. 不想每次執行時都帶著sudo,那就建立個docker給並把當前使用者加進去
sudo groupadd docker && sudo usermod -aG docker $USER
退出shell 再登入就可以不用sudo了 docker run hello-world
參考自: https://docs.docker.com/engine/installation/linux/ubuntu/
更多Docker相關教學見以下內容:
Docker安裝應用(CentOS 6.5_x64) http://www.linuxidc.com/Linux/2014-07/104595.htm
Ubuntu 16.04 伺服器上設定使用 Docker http://www.linuxidc.com/Linux/2017-06/145176.htm
Ubuntu 15.04下安裝Docker http://www.linuxidc.com/Linux/2015-07/120444.htm
Docker 安裝範例 http://www.linuxidc.com/Linux/2017-04/142666.htm
Docker 建立基礎映象 http://www.linuxidc.com/Linux/2017-05/144112.htm
在 Ubuntu 15.04 上如何安裝Docker及基本用法 http://www.linuxidc.com/Linux/2015-09/122885.htm
Ubuntu 16.04上Docker使用手記 http://www.linuxidc.com/Linux/2016-12/138490.htm
使用Docker分分鐘啟動常用應用 http://www.linuxidc.com/Linux/2017-04/142649.htm
Ubuntu 16.04下Docker修改組態檔不生效解決辦法 http://www.linuxidc.com/Linux/2017-05/143862.htm
相關文章