Centos7

  1. # 卸载旧docker
  2. sudo yum -y remove docker \
  3. docker-client \
  4. docker-client-latest \
  5. docker-common \
  6. docker-latest \
  7. docker-latest-logrotate \
  8. docker-logrotate \
  9. docker-engine
  10. # 安装docker依赖组件
  11. sudo yum -y install yum-utils \
  12. device-mapper-persistent-data \
  13. lvm2
  14. # 启用docker稳定库、使用阿里docker库yum源
  15. sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  16. # 安装docker
  17. sudo yum -y install docker-ce docker-ce-cli containerd.io
  18. # 开机启动与启动服务
  19. sudo systemctl enable docker
  20. sudo systemctl start docker
  21. # 自动补齐功能 centos7安装自动补全软件包,这样docker就可以自动补全,重新登陆shell才能生效
  22. yum -y install bash-completion

Debian

  1. # 添加软件源的 GPG 密钥
  2. curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg | sudo apt-key add -
  3. # 添加 Docker CE 软件源,add-apt-repository命令由apt-file包提供。
  4. apt-get install apt-file
  5. add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/debian $(lsb_release -cs) stable"
  6. # 安装docker-ce
  7. apt-get update
  8. apt-get install docker-ce
  9. apt-file update

Docker 使用国内源

编辑docker配置文件

  1. sudo cat > /etc/docker/daemon.json <<EOF
  2. {
  3. "registry-mirrors": [
  4. "https://kfwkfulq.mirror.aliyuncs.com",
  5. "https://2lqq34jg.mirror.aliyuncs.com",
  6. "https://pee6w651.mirror.aliyuncs.com",
  7. "https://registry.docker-cn.com",
  8. "http://hub-mirror.c.163.com"
  9. ],
  10. "dns": ["8.8.8.8","8.8.4.4"]
  11. }
  12. EOF

重启服务

重启服务国内源才能生效

  1. systemctl daemon-reload
  2. systemctl restart docker

验证是否生效

验证是否生效,有输出https地址表示已生效

  1. root@localhost# docker info | grep -A 6 "Registry Mirrors"
  2. Registry Mirrors:
  3. https://kfwkfulq.mirror.aliyuncs.com/
  4. https://2lqq34jg.mirror.aliyuncs.com/
  5. https://pee6w651.mirror.aliyuncs.com/
  6. https://registry.docker-cn.com/
  7. http://hub-mirror.c.163.com/
  8. https://dockerhub.azk8s.cn/

安装docker-compose

docker-compose是容器编排工具

  1. yum -y install epel-release
  2. yum -y install docker-compose

安装docker可视化

群辉的docker可视化还是挺不错的,这个portainer还是有点欠缺~~~

  1. docker run -d -p 9000:9000 \
  2. --restart=always \
  3. -v /var/run/docker.sock:/var/run/docker.sock \
  4. --name prtainer-test \
  5. portainer/portainer

瓦雀