官方文档链接地址:https://docs.docker.com/install/linux/docker-ce/ubuntu/#set-up-the-repository
一 卸载安装
1 卸载旧版本
sudo apt-get remove docker docker-engine docker.io
2 安装
方式一 脚本安装
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
方式二
(应该可以跳过)由于apt源使用HTTPS以确保软件下载过程中不被篡改。因此,我们首先需要添加使用HTTPS传输的软件包以及CA证书。
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
(应该可以跳过)为了确认所下载软件包的合法性,需要添加软件源的GPG密钥。
国内源:
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软件源
国内源:
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 社区版本)
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