Ubuntu上安装Docker CE


title: Ubuntu上安装Docker CE
tags: Docker CE


在Ubuntu上安装

卸载旧版本

sudo apt-get remove docker docker-engine docker.io

更新apt包索引

sudo apt-get update

安装依赖的包

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

添加Docker的GPG密钥

注意:这边要来坑了

  • 官方源
	$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

备注:可验证秘钥指纹 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88

你现在肯定在想,怎么出错了,上面的需要我们翻墙才能使用,所以强烈建议使用国内源。

  • 国内源
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

添加 Docker 软件源

当然这里的官方源还是不好用

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

所以我们应该使用国内源

  • 国内源
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"

再次更新apt包

我们已经添加好源了,所以我们需要再更新一次包。
sudo apt-get update

查看可用Docker 版本

apt-cache madison docker-ce
docker-ce | 18.03.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages

安装

  • 默认安装
    sudo apt-get install docker-ce
    使用上面的语句会默认帮我们安装最新的版本

  • 指定版本
    sudo apt-get install docker-ce=<VERSION>

如果需要安装其他版本我们在后面指定版本号就好了。

运行

  • 启动docker
    sudo systemctl start docker

  • 设置开机启动
    sudo systemctl enable docker

  • 实现helloworld
    docker run hello-world

镜像加速

由于国外的镜像有时候网络访问过慢,需要使用国内的镜像加速

对于使用 systemd 的系统,请在 /etc/docker/daemon.json 中写入如下内容(如果文件不存
在请新建该文件)

{
"registry-mirrors": [
    "https://registry.docker-cn.com"
    ]
}

之后重启启动系统

sudo systemctl daemon-reload
sudo systemctl restart docker
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值