查看ubuntu版本
root@ubuntu:~# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
root@ubuntu:~# uname -a
Linux ubuntu 4.15.0-29-generic #31-Ubuntu SMP
Tue Jul 17 15:39:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
root@ubuntu:~#
先卸載可能存在的舊版本
sudo apt-get remove docker docker-engine docker-ce docker.io
fcj@ubuntu:~$ sudo apt-get remove docker docker-engine docker-ce docker.io
[sudo] fcj 的密碼:
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹(shù)
正在讀取狀態(tài)信息... 完成
軟件包 docker-engine 未安裝,所以不會(huì)被卸載
軟件包 docker-ce 未安裝,所以不會(huì)被卸載
軟件包 docker 未安裝,所以不會(huì)被卸載
軟件包 docker.io 未安裝,所以不會(huì)被卸載
升級(jí)了 0 個(gè)軟件包,新安裝了 0 個(gè)軟件包,要卸載 0 個(gè)軟件包,有 329 個(gè)軟件包未被升級(jí)。
更新apt包
sudo apt-get update
fcj@ubuntu:~$ sudo apt-get update
命中:1 http://us.archive.ubuntu.com/ubuntu bionic InRelease
獲取:2 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
獲取:3 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
獲取:4 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
獲取:5 http://us.archive.ubuntu.com/ubuntu bionic/main Translation-zh_CN [67.7 kB]
獲取:6 http://us.archive.ubuntu.com/ubuntu bionic/main Translation-en_AU [430 kB]
獲取:7 http://us.archive.ubuntu.com/ubuntu bionic/restricted Translation-en_AU [1,340 B]
獲取:8 http://us.archive.ubuntu.com/ubuntu bionic/restricted Translation-zh_CN [1,188 B]
獲取:9 http://us.archive.ubuntu.com/ubuntu bionic/universe Translation-zh_CN [174 kB]
獲取:10 http://us.archive.ubuntu.com/ubuntu bionic/universe Translation-en_AU [4,118 kB]
獲取:11 http://us.archive.ubuntu.com/ubuntu bionic/multiverse Translation-zh_CN [4,768 B]
獲取:12 http://us.archive.ubuntu.com/ubuntu bionic/multiverse Translation-en_AU [63.5 kB]
已下載 5,107 kB,耗時(shí) 39秒 (129 kB/s)
正在讀取軟件包列表... 完成
切換到root權(quán)限
sudo -i
fcj@ubuntu:~$ sudo -i
root@ubuntu:~# 123456
123456:未找到命令
root@ubuntu:~#
安裝以下包以使apt可以通過(guò)HTTPS使用存儲(chǔ)庫(kù)(repository):
ubuntu:~# apt-get install apt-transport-https \ ca-certificates \ curl \ software-properties-common
root@ubuntu:~# apt-get install \
> apt-transport-https \
> ca-certificates \
> curl \
> software-properties-common
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹(shù)
正在讀取狀態(tài)信息... 完成
ca-certificates 已經(jīng)是最新版 (20180409)。
將會(huì)同時(shí)安裝下列軟件:
libcurl4 python3-software-properties software-properties-gtk
下列【新】軟件包將被安裝:
apt-transport-https curl libcurl4
下列軟件包將被升級(jí):
python3-software-properties software-properties-common
software-properties-gtk
升級(jí)了 3 個(gè)軟件包,新安裝了 3 個(gè)軟件包,要卸載 0 個(gè)軟件包,有 326 個(gè)軟件包未被升級(jí)。
需要下載 374 kB/460 kB 的歸檔。
解壓縮后會(huì)消耗 1,188 kB 的額外空間。
您希望繼續(xù)執(zhí)行嗎? [Y/n] y
獲取:1 http://us.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 apt-transport-https all 1.6.6 [1,692 B]
獲取:2 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libcurl4 amd64 7.58.0-2ubuntu3.5 [214 kB]
獲取:3 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 curl amd64 7.58.0-2ubuntu3.5 [159 kB]
已下載 374 kB,耗時(shí) 3秒 (140 kB/s)
正在選中未選擇的軟件包 apt-transport-https。
(正在讀取數(shù)據(jù)庫(kù) ... 系統(tǒng)當(dāng)前共安裝有 127925 個(gè)文件和目錄。)
正準(zhǔn)備解包 .../0-apt-transport-https_1.6.6_all.deb ...
正在解包 apt-transport-https (1.6.6) ...
正在選中未選擇的軟件包 libcurl4:amd64。
正準(zhǔn)備解包 .../1-libcurl4_7.58.0-2ubuntu3.5_amd64.deb ...
正在解包 libcurl4:amd64 (7.58.0-2ubuntu3.5) ...
正在選中未選擇的軟件包 curl。
正準(zhǔn)備解包 .../2-curl_7.58.0-2ubuntu3.5_amd64.deb ...
正在解包 curl (7.58.0-2ubuntu3.5) ...
正準(zhǔn)備解包 .../3-software-properties-common_0.96.24.32.6_all.deb ...
正在將 software-properties-common (0.96.24.32.6) 解包到 (0.96.24.32.4) 上 ...
正準(zhǔn)備解包 .../4-software-properties-gtk_0.96.24.32.6_all.deb ...
正在將 software-properties-gtk (0.96.24.32.6) 解包到 (0.96.24.32.4) 上 ...
正準(zhǔn)備解包 .../5-python3-software-properties_0.96.24.32.6_all.deb ...
正在將 python3-software-properties (0.96.24.32.6) 解包到 (0.96.24.32.4) 上 ...
正在設(shè)置 apt-transport-https (1.6.6) ...
正在處理用于 mime-support (3.60ubuntu1) 的觸發(fā)器 ...
正在處理用于 desktop-file-utils (0.23-1ubuntu3.18.04.1) 的觸發(fā)器 ...
正在處理用于 libglib2.0-0:amd64 (2.56.1-2ubuntu1) 的觸發(fā)器 ...
正在設(shè)置 libcurl4:amd64 (7.58.0-2ubuntu3.5) ...
正在處理用于 libc-bin (2.27-3ubuntu1) 的觸發(fā)器 ...
正在處理用于 man-db (2.8.3-2) 的觸發(fā)器 ...
正在處理用于 shared-mime-info (1.9-2) 的觸發(fā)器 ...
正在設(shè)置 python3-software-properties (0.96.24.32.6) ...
正在處理用于 gnome-menus (3.13.3-11ubuntu1) 的觸發(fā)器 ...
正在處理用于 dbus (1.12.2-1ubuntu1) 的觸發(fā)器 ...
正在處理用于 hicolor-icon-theme (0.17-2) 的觸發(fā)器 ...
正在設(shè)置 software-properties-common (0.96.24.32.6) ...
正在設(shè)置 curl (7.58.0-2ubuntu3.5) ...
正在設(shè)置 software-properties-gtk (0.96.24.32.6) ...
添加Docker官方的GPG密鑰:
root@ubuntu:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK
安裝穩(wěn)定存儲(chǔ)庫(kù)
sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \stable"
再更新一下apt包索引:
apt-get update
root@ubuntu:~# apt-get update
獲取:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
命中:2 http://us.archive.ubuntu.com/ubuntu bionic InRelease
命中:3 https://download.docker.com/linux/ubuntu artful InRelease
獲取:4 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
獲取:5 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
已下載 247 kB,耗時(shí) 2秒 (103 kB/s)
正在讀取軟件包列表... 完成
安裝完成 檢驗(yàn)是否安裝成功
docker version
:顯示docker版本信息
docker run hello-world
:運(yùn)行下hello-world檢驗(yàn)下是否運(yùn)行成功
root@ubuntu:~# docker version
Client:
Version: 18.06.1-ce
API version: 1.38
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:25:03 2018
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.06.1-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:23:27 2018
OS/Arch: linux/amd64
Experimental: false
root@ubuntu:~# 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.
(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/get-started/
Docker 常用命令
啟動(dòng)docker
sudo service docker start停止docker
sudo service docker stop重啟docker
sudo service docker restart列出Docker CLI命令
docker
docker container --help顯示Docker版本和信息
docker --version
docker version
docker infoExecute Docker image
docker run hello-world列出鏡像列表
docker image ls列出docker容器 (running, all, all in quiet mode)
docker container ls
docker container ls --all
docker container ls -aq
啟用鏡像加速:
鑒于國(guó)內(nèi)網(wǎng)絡(luò)問(wèn)題,后續(xù)拉取 Docker 鏡像十分緩慢,我們可以需要配置加速器來(lái)解決,我使用的是阿里云的鏡像地址:
https://xxxxxxxx.mirror.aliyuncs.com(可以區(qū)阿里云免費(fèi)申請(qǐng)一個(gè))
新版的 Docker 使用 /etc/docker/daemon.json(Linux) 或者 %programdata%\docker\config\daemon.json(Windows) 來(lái)配置 Daemon。
請(qǐng)?jiān)谠撆渲梦募屑尤耄](méi)有該文件的話,請(qǐng)先建一個(gè)):
{
"registry-mirrors":["https://xxxxxxxx.mirror.aliyuncs.com"]
}