2.Ubuntu安装 Docker

平台支持

Docker CE 支持多种平台,如下表所示

桌面

平台架构
Docker Desktop for Mac (macOS) X64
Docker Desktop for Windows (Microsoft Windows 10) X64

服务器

平台x86_64 / amd64ARMARM64 / AARCH64IBM Power (ppc64le)IBM Z (s390x)
CentOS      
Debian    
Fedora      
Ubuntu

准备安装

卸载旧版本

  1. apt-get remove docker docker-engine docker.io containerd runc

使用 APT 安装

  1. # 更新数据源
  2. apt-get update
  3. # 安装所需依赖
  4. apt-get -y install apt-transport-https ca-certificates curl software-properties-common
  5. # 安装 GPG 证书
  6. curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
  7. # 新增数据源
  8. add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
  9. # 更新并安装 Docker CE
  10. apt-get update && apt-get install -y docker-ce

验证安装是否成功

  1. docker version
  2. # 输出如下
  3. Client:
  4. Version18.09.6
  5. API version1.39
  6. Go version: go1.10.8
  7. Git commit481bc77
  8. BuiltSat May 02:35:57 2019
  9. OS/Arch: linux/amd64
  10. Experimental: false
  11. ServerDocker Engine Community
  12. Engine:
  13. Version18.09.6
  14. API version1.39 (minimum version 1.12)
  15. Go version: go1.10.8
  16. Git commit481bc77
  17. BuiltSat May 01:59:36 2019
  18. OS/Arch: linux/amd64
  19. Experimental: false

配置 Docker 镜像加速器

阿里云加速器(推荐)

点击链接获取

官方提供中国区镜像

  1. https://registry.docker-cn.com

配置加速器

以配置阿里云加速器为例,首先 登录阿里云(没有账号请先注册),搜索 容器镜像服务

找到你的专属加速器

通过修改 daemon 配置文件 /etc/docker/daemon.json 来使用加速器

  1. tee /etc/docker/daemon.json <<-'EOF'
  2. {
  3. "registry-mirrors"["https://xxxxxxxx.mirror.aliyuncs.com"]
  4. }
  5. EOF
  6. # 重启 Docker
  7. systemctl daemon-reload
  8. systemctl restart docker

若出现:systemctl: command not found

执行  apt-get install –reinstall systemd

验证配置是否成功

  1. docker info
  2. # 输出如下
  3. Containers38
  4. Running18
  5. Paused0
  6. Stopped20
  7. Images10
  8. Server Version18.09.6
  9. Storage Driver: overlay2
  10. Backing Filesystem: extfs
  11. Supports d_type: true
  12. Native Overlay Diff: true
  13. Logging Driver: json-file
  14. Cgroup Driver: cgroupfs
  15. Plugins:
  16. Volumelocal
  17. Network: bridge host macvlan null overlay
  18. Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
  19. Swarm: inactive
  20. Runtimes: runc
  21. Default Runtime: runc
  22. Init Binary: docker-init
  23. containerd version: bb71b10fd8f58240ca47fbb579b9d1028eea7c84
  24. runc version2b18fe1d885ee5083ef9f0838fee39b62d653e30
  25. init version: fec3683
  26. Security Options:
  27. apparmor
  28. seccomp
  29. Profile: default
  30. Kernel Version4.15.0-51-generic
  31. Operating SystemUbuntu 18.04.2 LTS
  32. OSType: linux
  33. Architecture: x86_64
  34. CPUs2
  35. Total Memory1.924GiB
  36. Name: kubernetes-master
  37. ID: PJ4H:7AF2:P5UT:6FMR:W4DI:SSWR:IQQR:J6QO:ARES:BOAC:ZVMO:SV2Y
  38. Docker Root Dir/var/lib/docker
  39. Debug Mode (client): false
  40. Debug Mode (server): false
  41. Registry: https://index.docker.io/v1/
  42. Labels:
  43. Experimental: false
  44. Insecure Registries:
  45. 127.0.0.0/8
  46. ## 这里是你配置的镜像加速器
  47. Registry Mirrors:
  48. https://xxxxxxxx.mirror.aliyuncs.com/
  49. Live Restore Enabled: false
  50. Product LicenseCommunity Engine
  51. WARNINGNo swap limit support

运行第一个容器

我们以 Nginx 为例,体验 Docker 是如何运行容器的

  1. # 下载镜像
  2. docker pull nginx
  3. # 运行容器
  4. docker run --name nginx-container -80:80 -d nginx

浏览器输入虚拟机地址即可访问 Nginx

其它安装方法

  • 安装命令
  1. sudo apt install docker.io
  • 解决普通用户不能直接使用 docker 命令
  1. docker ps
  2. Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sockGet http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/json: dial unix /var/run/docker.sock: connect: permission denied
  1. # 创建 docker 用户组
  2. sudo groupadd docker
  3. # 添加当前用户到 docker 组
  4. sudo usermod -aG docker $USER
  5. # 重启 docker
  6. sudo systemctl restart docker
  7. newgrp - docker
  8. # 重启系统
  9. sudo reboot

本文来自博客园,作者:l-coil,转载请注明原文链接:https://www.cnblogs.com/l-coil/p/12369169.html

原文地址:https://www.cnblogs.com/xianquan/p/12369169.html