Ubuntu 安裝 docker-ce

[TOC]

官方腳本安裝

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

這里直接使用批量腳本,通過阿里云鏡像安裝,如果想掌握安裝過程,需要繼續(xù)往下看

使用阿里云鏡像安裝

參考官方文檔 https://yq.aliyun.com/articles/110806?spm=5176.8351553.0.0.6a721991LqELWA

# step 1: 安裝必要的一些系統(tǒng)工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安裝GPG證書
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 寫入軟件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安裝 Docker-CE
sudo apt-get update
sudo apt-get -y install docker-ce
# 安裝的版本可能很低,建議更換后面的方式安裝
sudo apt-get -y install docker-compose
# python-pip
sudo apt-get -y install python-pip
# update pip
sudo pip install --upgrade pip
# install docker-compose
sudo pip install docker-compose
# Cannot uninstall 'texttable'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
sudo pip install docker-compose --ignore-installed texttable

# 安裝指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# apt-cache madison docker-ce
# docker-ce | 17.03.1~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages
# docker-ce | 17.03.0~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages
# Step 2: 安裝指定版本的Docker-CE: (VERSION 例如上面的 17.03.1~ce-0~ubuntu-xenial)
# sudo apt-get -y install docker-ce=[VERSION]

16.04 安裝

  • set resource
# update package
sudo apt-get update
# Install packages
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
# add GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# set up the stable repository
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
  • install docker-ce
sudo apt-get update
sudo apt-get install docker-ce
  • Uninstall Docker CE
# Uninstall the Docker CE package
sudo apt-get purge docker-ce
# remove  Images, containers, volumes, or customized configuration files
sudo rm -rf /var/lib/docker

tips: You must delete any edited configuration files manually

14.04安裝docker

通過apt-get安裝

apt-get update
apt-get install docker.io
ln -sf /usr/bin/docker.io /usr/local/bin/docker
sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/docker.io
apt-get install apt-transport-https
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
sh -c "echo deb https://get.docker.io/ubuntu docker main  > /etc/apt/sources.list.d/docker.list"
apt-get update
apt-get install lxc-docker

通過下載二進制文件安裝

curl -sSL https://get.docker.com/ | sh

安裝過程輸出

#查看index.htmlkkk@bogon:~$ sudo apt-get install vim
Reading package lists... Done
Building dependency tree      
Reading state information... Done
vim is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 32 not upgraded.
kkk@bogon:~$ vi ./index.html
# Check that HTTPS transport is available to APT
if [ ! -e /usr/lib/apt/methods/https ]; then
        apt-get update
        apt-get install -y apt-transport-https
fi
 
# Add the repository to your APT sources
echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.lis
t
 
# Then import the repository key
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F96
6E92D8576A8BA88D21E9
 
# Install docker
apt-get update
apt-get install -y lxc-docker
 
#
# Alternatively, just use the curl-able install.sh script provided at https://get.dock
er.io
#
~                                                                                    
"./index.html" 19L, 584C                                            1,1           All
# Check that HTTPS transport is available to APT
if [ ! -e /usr/lib/apt/methods/https ]; then
        apt-get update
        apt-get install -y apt-transport-https
fi
 
# Add the repository to your APT sources
echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.lis
t
 
# Then import the repository key
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F96
6E92D8576A8BA88D21E9
 
# Install docker
apt-get update
apt-get install -y lxc-docker
 
#
# Alternatively, just use the curl-able install.sh script provided at https://get.dock
er.io
#
~

這種方式啟動docker若出現(xiàn)下面錯誤,請安裝apparmor軟件

Error loading docker apparmor profile: fork/exec /sbin/apparmor_parser: no such file or directory () 
sudo apt-get install apparmor

安裝后檢查安裝

sudo docker run hello-world

sudo docker pull daocloud.io/library/ubuntu:latest

去除每次sudo運行docker命令

需要添加組

# Add the docker group if it doesn't already exist.
$ sudo groupadd docker
#改完后需要重新登陸用戶
$ sudo gpasswd -a ${USER} docker
# 更新用戶組
$ newgrp docker

不要讓docker 運行在 root 下,所以給某個用戶 docker 運行權(quán)限是必要的

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容