1. 程式人生 > 實用技巧 >Docker01——Ubuntu上安裝Docker

Docker01——Ubuntu上安裝Docker

學習Docker之前要先安裝好,下面來談談安裝步驟,本人直接copy官網上的安裝步驟,只不過將各個步驟編寫成了一個Shell檔案(最底下),直接執行即可,只需要注意以下地方
1.輸入docker-ce的版本號

這裡需要copy上面展示出的版本號,然後粘貼後按enter鍵
2.對於詢問的地方,直接輸入Y

據統計,出現確認的地方應該有兩處,最後出現如下輸出就表示安裝好了docker容器

3.如果執行指令碼檔案的時候出現錯誤,如:

line 1: $'\r': command not found


這是因為在windows的記事本之中換行符和Linux系統之中不一樣導致的,解決方案:
vi編輯器

或者vim開啟檔案,然後在命令模式下輸入:

set ff=unix

然後儲存即可
下面是官網的安裝程式碼,儲存到某個.sh檔案中,然後執行即可

# Older versions of Docker were called docker, docker.io, or docker-engine. If these are installed, uninstall them:
sudo apt-get remove docker docker-engine docker.io containerd runc
# Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt-get update

sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
# Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

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

# INSTALL DOCKER ENGINE
# 1.Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
# 2.To install a specific version of Docker Engine, list the available versions in the repo, then select and install:
apt-cache madison docker-ce
# 2.1 List the versions available in your repo:
read -p "Please input a docker-ce version:" VERSION_STRING
# 2.2 Install a specific version using the version string from the second column, for example, 5:18.09.1~3-0~ubuntu-xenial.
sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io
# 2.3 Verify that Docker Engine is installed correctly by running the hello-world image.
sudo docker run hello-world

參考文章

[1] Install Docker Engine on Ubuntu