ubuntu18.04安装docker

 

阿里云 apt仓库

$ curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

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

再更新一下apt包索引:

sudo apt-get update

安装最新版本的Docker CE:

sudo apt-get install -y docker-ce

出现如下问题时:

dpkg:处理 smbclient (--configure)时出错:
 依赖关系问题 - 仍未被配置
因为错误消息指示这是由于上一个问题导致的错误,没有写入 apport 报告。
                                                          由于已经达到 MaxReports 限制,没有写入 apport 报告。
                                        在处理时有错误发生:
 nfs-common
 samba-common
 samba
 smbclient
E: Sub-process /usr/bin/dpkg returned an error code (1)

采用如下解决方案可以解决:

解决办法如下:


1.将info文件夹更名


sudo mv /var/lib/dpkg/info /var/lib/dpkg/info_old
2再新建一个新的info文件夹


sudo mkdir /var/lib/dpkg/info
3.更新
sudo apt-get update
<pre name="code" class="plain">sudo apt-get -f install
4.执行完上一步操作后会在新的info文件夹下生成一些文件,现将这些文件全部移到info_old文件夹下

sudo mv /var/lib/dpkg/info/* /var/lib/dpkg/info_old 
5.把自己新建的info文件夹删掉

sudo rm -rf /var/lib/dpkg/info
6.把以前的info文件夹重新改回名字

sudo mv /var/lib/dpkg/info_old /var/lib/dpkg/info 
问题解决。

这里安装的最新版,其实是安装你电脑上可用的最新版,查看系统可用的版本:

apt-cache madison docker-ce

选择要安装的特定版本,第二列是版本字符串,第三列是存储库名称,它指示包来自哪个存储库,以及扩展它的稳定性级别。要安装一个特定的版本,将版本字符串附加到包名中,并通过等号(=)分隔它们:

sudo apt-get install docker-ce=<VERSION>

验证docker

查看docker服务是否启动:

systemctl status docker

若未启动,则启动docker服务:

sudo systemctl start docker

测试经典的hello world:

sudo docker run hello-world

更新为国内镜像仓库

国内镜像仓库地址:

https://registry.docker-cn.com

http://hub-mirror.c.163.com

https://3laho3y3.mirror.aliyuncs.com

http://f1361db2.m.daocloud.io

https://mirror.ccs.tencentyun.com

https://hub.daocloud.io

方案1:修改docker配置文件

sudo vi /etc/docker/daemon.json

 添加如下内容:

{
    "registry-mirrors": ["http://hub-mirror.c.163.com"]
}

 方案2:通过修改启动脚本配置加速站点

# 直接修改 /usr/lib/systemd/system/docker.service 启动脚本
vi /usr/lib/systemd/system/docker.service
# 在dockerd后面加参数
ExecStart=/usr/bin/dockerd --registry-mirror=<your accelerate address>

 以上操作后重启一下 Docker

sudo systemctl daemon-reload
sudo systemctl restart docker

 验证

wzl@DIY-PC:~$ sudo docker info
Client:
 Debug Mode: false

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 10
 Server Version: 19.03.12
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.3.0-18-generic
 Operating System: Ubuntu 19.10
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 31.31GiB
 Name: DIY-PC
 ID: AYRN:CQSV:OWOI:R2BP:ZLIB:AMUO:XLBH:UREU:ID5J:ERYX:V6XF:P4RO
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  http://hub-mirror.c.163.com/
 Live Restore Enabled: false

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值