Docker学习笔记(二)——Docker安装
阿里云Ubuntu 16.04 LTS 64位系统安装Docker-CE
Docker CE(Community Edition),即Docker社区版,是开发人员和小型团队的理想选择。
step 1: 安装必要的一些系统工具
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 -y update
sudo apt-get -y install docker-ce
上面命令默认安装最新版本,若想安装指定版本的Docker-CE:
Step 4.1: 查找Docker-CE的版本:
apt-cache madison docker-ce
Step 4.2: 安装指定版本的Docker-CE: (把下面VERSION改成指定版本即可)
sudo apt-get -y install docker-ce=[VERSION]
Step 5: 查看docker是否启动
systemctl status docker
Step 6: 若未启动,则启动docker服务
sudo systemctl start docker
服务启动
Step 7: 永远的hello world ==> run hello world验证
sudo docker run hello-world
如出现下图,则证明安装成功。
成功运行hello-world
可能遇到的问题:
问题1:
Err:2 https://download.docker.com/linux/ubuntu xenial/stable amd64 docker-ce-cli amd64 5:19.03.53-0ubuntu-xenial
Operation too slow. Less than 10 bytes/sec transferred the last 120 seconds
Err:3 https://download.docker.com/linux/ubuntu xenial/stable amd64 docker-ce amd64 5:19.03.53-0ubuntu-xenial
Could not resolve host: download.docker.com E: Failed to fetch https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/containerd.io_1.2.10-3_amd64.deb Operation too slow. Less than 10 bytes/sec transferred the last 120 seconds
E: Failed to fetch https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-ce-cli_19.03.53-0ubuntu-xenial_amd64.deb Operation too slow. Less than 10 bytes/sec transferred the last 120 seconds
E: Failed to fetch https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-ce_19.03.53-0ubuntu-xenial_amd64.deb Could not resolve host: download.docker.com
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
原因:外网镜像源下载速度慢?
解决方法:更换国内阿里云证书和软件源,如上面step2和step3所示。
问题2:运行sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
出现
E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
原因:其他过程正在占用apt,找到该进程杀死即可
解决方法:
ps aux | grep -i apt
运行上面命令查看占用apt的进程id
使用sudo kill -9 <进程ID>
或sudo killall apt-get
杀死进程即可。
参考:
https://help.aliyun.com/document_detail/60742.html
https://blog.csdn.net/BingZhongDeHuoYan/article/details/79411479