官方文档连接地址:https://docs.docker.com/install/linux/docker-ce/ubuntu/#set-up-the-repositorylinux
一 卸载安装docker
1 卸载旧版本shell
sudo apt-get remove docker docker-engine docker.io
2 安装ubuntu
方式一 脚本安装curl
curl -fsSL get.docker.com -o get-docker.sh * curl -f 链接失败时不显示HTTP错误信息 * curl -s Silent模式。不输出任务内容 * curl -S 显示错误. 在选项 -s 中,当 curl 出现错误时将显示 * curl -L 跟踪重定向 * curl -o 将输出写入文件,而非 stdout sudo sh get-docker.sh --mirror Aliyun
方式二this
(应该能够跳过)因为apt源使用HTTPS以确保软件下载过程当中不被篡改。所以,咱们首先须要添加使用HTTPS传输的软件包以及CA证书。url
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
(应该能够跳过)为了确认所下载软件包的合法性,须要添加软件源的GPG密钥。spa
国内源: curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add - 官方源: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
而后,咱们须要向 source.list 中添加Docker软件源code
国内源: sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" 官方源: sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
安装docker ce (ce 社区版本)rem
sudo apt-get update sudo apt-get install docker-ce
*********************************************************************************************************
*** 安装完成以后,会多一个docker用户组。默认只有docker组和root用户能够使用。
执行 sudo usermod -aG docker your-user 用户添加到docker组里,
Run this command in your favourite shell and then completely log out of your account and log back in (if in doubt, reboot!):
重启系统以后,就能够使用设置用户使用docker了。
*********************************************************************************************************
*** 进入/etc/下
user@user: ll |grep docker drwx------ 2 root root 4096 4月 4 10:41 docker/
更改docker文件夹组属性(非必须)
user@user:/etc$ sudo chgrp -R docker docker/ user@user:/etc$ ll | grep docker drwx------ 2 root docker 4096 4月 4 10:41 docker/ user@user:/etc$ sudo chmod -R 770 docker/ user@user:/etc$ ll | grep docker drwxrwx--- 2 root docker 4096 4月 4 10:41 docker/
*********************************************************************************************************
3 彻底卸载
sudo apt-get purge docker-ce sudo rm -rf /var/lib/docker
二 设置镜像加速器
使用阿里的docker镜像服务 访问:https://cr.console.aliyun.com/ 注册以后,在镜像加速器就能够看到设置方法。
三 hello world
执行该命令:会下载hello-world镜像,而后执行。
docker run hello-world
查看下载镜像
docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest f2a91732366c 4 months ago 1.85kB
删除镜像
docker image rm -f hello-world:latest Untagged: hello-world:latest Untagged: hello-world@sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1 Deleted: sha256:f2a91732366c0332ccd7afd2a5c4ff2b9af81f549370f7a19acd460f87686bc7 user@user:/etc/docker$ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE 说明 docker image rm --help Usage: docker image rm [OPTIONS] IMAGE [IMAGE...] Remove one or more images Aliases: rm, rmi, remove Options: -f, --force Force removal of the image --no-prune Do not delete untagged parents