在Ubuntu作業系統裡安裝Docker

i042416發表於2018-09-20

Docker 是一個開源的應用容器引擎,讓開發者可以打包他們的應用以及依賴包到一個可移植的容器中,然後釋出到任何流行的 Linux 機器上,也可以實現虛擬化。容器是完全使用沙箱機制,相互之間不會有任何介面。

今天這篇文章我們們就來將Docker安裝到Ubuntu上。

1. 由於Ubuntu裡apt官方庫裡的docker版本可能比較低,因此先用下面的命令列解除安裝舊版本(如果有的話)

sudo apt-get remove docker docker-engine docker-ce docker.io

在Ubuntu作業系統裡安裝Docker

2. 更新apt包索引:

sudo apt-get update

在Ubuntu作業系統裡安裝Docker

3. 執行下列命令列,使apt可以通過HTTPS協議去使用儲存庫:

sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common

4. 新增Docker官方提供的GPG金鑰:

curl -fsSL  https://download.docker.com/linux/ubuntu/gpg  | sudo apt-key add -

什麼是GPG金鑰呢?大家可以從阮一峰老師的部落格:GPG入門教程裡獲得答案:

1991年,程式設計師Phil Zimmermann為了避開政府監視,開發了加密軟體PGP。這個軟體非常好用,迅速流傳開來,成了許多程式設計師的必備工具。但是,它是商業軟體,不能自由使用。所以,自由軟體基金會決定,開發一個PGP的替代品,取名為GnuPG。這就是GPG的由來。

上面的文字出自阮一峰老師的部落格連結: http://www.ruanyifeng.com/blog/2013/07/gpg.html

5. 設定stable儲存庫:

sudo add-apt-repository "deb [arch=amd64]  https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

最後再次更新apt包索引:

6. 安裝最新版本的docker-ce:

sudo apt-get install -y docker-ce

安裝完畢後,可以看到Docker服務已經從/lib/systemd/system/docker.service啟動了,dockerd程式id為4921:

在Ubuntu作業系統裡安裝Docker

命令列ps -aux檢視程式id為4921的程式路徑:/usr/bin/dockerd -H fd://

在Ubuntu作業系統裡安裝Docker

使用命令sudo docker version可以檢視安裝docker的版本:

在Ubuntu作業系統裡安裝Docker

使用命令sudo docker run hello-world,能觀察到從遠端下載這個測試用的容器:Pulling from library/hello-world:

然後看到列印訊息:Hello from Docker! 說明Docker安裝成功。

在Ubuntu作業系統裡安裝Docker

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.

(amd64)

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://hub.docker.com/

For more examples and ideas, visit:

https://docs.docker.com/engine/userguide/

要獲取更多Jerry的原創技術文章,請關注公眾號"汪子熙"或者掃描下面二維碼:


在Ubuntu作業系統裡安裝Docker

在Ubuntu作業系統裡安裝Docker


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2214561/,如需轉載,請註明出處,否則將追究法律責任。

相關文章