可以在任何作業系統上安裝Docker,無論是Mac,Windows,Linux還是任何雲伺服器。Docker 引擎在Linux發行版上執行。 在這裡,我們將以Linux Ubuntu Xenial-16.04 [LTS]作為演示安裝Docker引擎的過程。
Docker需要兩個重要的安裝要求:
3.10
或更高版本。要檢視當前的核心版本,請開啟終端並鍵入uname -r
命令以檢視核心版本:
檢視核心版本命令如下:
yiibai@ubuntu:~$ uname -r
4.4.0-31-generic
yiibai@ubuntu:~$
檢視作業系統是32位元還是64位元:
yiibai@ubuntu:~$ sudo uname --m
[sudo] password for yiibai:
x86_64
yiibai@ubuntu:~$
按照以下說明更新apt
源。
sudo
命令作為root
使用者登入。命令:
yiibai@ubuntu:~$ sudo apt-get update
yiibai@ubuntu:~$ sudo apt-get install apt-transport-http ca-certificates
參見下面的螢幕截圖 -
yiibai@ubuntu:~$ sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
如下所示 -
yiibai@ubuntu:~$ sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
Executing: /tmp/tmp.Eix5oqerzZ/gpg.1.sh --keyserver
hkp://ha.pool.sks-keyservers.net:80
--recv-keys
58118E89F3A912897C070ADBF76221572C52609D
gpg: requesting key 2C52609D from hkp server ha.pool.sks-keyservers.net
gpg: key 2C52609D: public key "Docker Release Tool (releasedocker) <[email protected]>" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
yiibai@ubuntu:~$
yiibai@ubuntu:~$ echo "<REPO>" | sudo tee /etc/apt/sources.list.d/docker.list
執行上面命令,輸出結果如下 -
yiibai@ubuntu:~$ echo "<REPO>" | sudo tee /etc/apt/sources.list.d/docker.list
<REPO>
yiibai@ubuntu:~$
/etc/apt/sources.list.d/docker.list
並將以下行貼上到檔案中。deb http://apt.dockerproject.org/repo ubuntu-xenial main
使用 vi 建立並開啟檔案 /etc/apt/sources.list.d/docker.list
如下所示 -
yiibai@ubuntu:~$ sudo vi /etc/apt/sources.list.d/docker.list
yiibai@ubuntu:~$
yiibai@ubuntu:~$ sudo apt-get update
執行更新apt包索引,新增 docker 源地址,上面語句執行結果如下 -
yiibai@ubuntu:~$ sudo apt-get update
Get:1 http://apt.dockerproject.org/repo ubuntu-xenial InRelease [48.7 kB]
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:3 http://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages [4,177 B]
Hit:4 http://nginx.org/packages/ubuntu xenial InRelease
Hit:5 http://us.archive.ubuntu.com/ubuntu xenial InRelease
Get:6 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Fetched 359 kB in 20s (17.3 kB/s)
Reading package lists... Done
yiibai@ubuntu:~$
yiibai@ubuntu:~$ sudo apt-cache policy docker-engine
上面語句執行結果如下 -
yiibai@ubuntu:~$ sudo apt-cache policy docker-engine
docker-engine:
Installed: (none)
Candidate: 17.05.0~ce-0~ubuntu-xenial
Version table:
17.05.0~ce-0~ubuntu-xenial 500
500 http://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
17.04.0~ce-0~ubuntu-xenial 500
500 http://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
17.03.1~ce-0~ubuntu-xenial 500
500 http://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
... ...
... ...
1.11.0-0~xenial 500
500 http://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
yiibai@ubuntu:~$
yiibai@ubuntu:~$ sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
執行上面安裝命令,輸出結果如下 -
yiibai@ubuntu:~$ sudo apt-get install linux-image-extra-$(uname -r) linux-image- extra-virtual
Reading package lists... Done
Building dependency tree
Reading state information... Done
linux-image-extra-4.4.0-31-generic is already the newest version (4.4.0-31.50).
linux-image-extra-4.4.0-31-generic set to manually installed.
The following additional packages will be installed:
linux-generic linux-headers-4.4.0-78 linux-headers-4.4.0-78-generic
linux-headers-generic linux-image-4.4.0-78-generic
linux-image-extra-4.4.0-78-generic linux-image-generic
Suggested packages:
fdutils linux-doc-4.4.0 | linux-source-4.4.0 linux-tools
Recommended packages:
... ...
... ...
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.4.0-78-generic
Found initrd image: /boot/initrd.img-4.4.0-78-generic
Found linux image: /boot/vmlinuz-4.4.0-31-generic
Found initrd image: /boot/initrd.img-4.4.0-31-generic
done
Setting up linux-image-generic (4.4.0.78.84) ...
Setting up linux-headers-4.4.0-78 (4.4.0-78.99) ...
Setting up linux-headers-4.4.0-78-generic (4.4.0-78.99) ...
Setting up linux-headers-generic (4.4.0.78.84) ...
Setting up linux-generic (4.4.0.78.84) ...
Setting up linux-image-extra-virtual (4.4.0.78.84) ...
yiibai@ubuntu:~$
yiibai@ubuntu:~$ sudo apt-get update
執行上面程式碼,結果如下 -
yiibai@ubuntu:~$ sudo apt-get update
[sudo] password for yiibai:
Hit:1 http://apt.dockerproject.org/repo ubuntu-xenial InRelease
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Hit:3 http://us.archive.ubuntu.com/ubuntu xenial InRelease
Get:4 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Hit:5 http://nginx.org/packages/ubuntu xenial InRelease
Get:6 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Fetched 306 kB in 9s (31.2 kB/s)
Reading package lists... Done
yiibai@ubuntu:~$
yiibai@ubuntu:~$ sudo apt-get install docker-engine
執行上面程式碼,結果如下 -
yiibai@ubuntu:~$ sudo apt-get install docker-engine
... ...
... ...
update-alternatives: using /usr/bin/prename to provide /usr/bin/rename (rename) in auto mode
Setting up aufs-tools (1:3.2+20130722-1.1ubuntu1) ...
Setting up cgroupfs-mount (1.2) ...
Setting up libltdl7:amd64 (2.4.6-0.1) ...
Setting up docker-engine (17.05.0~ce-0~ubuntu-xenial) ...
Setting up liberror-perl (0.17-1.2) ...
Setting up git-man (1:2.7.4-0ubuntu1.1) ...
Setting up git (1:2.7.4-0ubuntu1.1) ...
Setting up patch (2.7.5-1) ...
Setting up rename (0.20-4) ...
update-alternatives: using /usr/bin/file-rename to provide /usr/bin/rename (rename) in auto mode
Setting up xz-utils (5.1.1alpha+20120614-2ubuntu2) ...
update-alternatives: using /usr/bin/xz to provide /usr/bin/lzma (lzma) in auto mode
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Processing triggers for systemd (229-4ubuntu7) ...
Processing triggers for ureadahead (0.100.0-19) ...
yiibai@ubuntu:~$
yiibai@ubuntu:~$ sudo service docker start
hello-world
映像來驗證Docker是否正確安裝。yiibai@ubuntu:~$ sudo docker run hello-world
如下面的螢幕截圖 -
以上命令下載測試映像並在容器中執行。當容器執行時,它會列印一條訊息並退出。