curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
或者
curl -sSL https://get.daocloud.io/docker | sh
测试:
sudo docker run hello-world
出现问题:
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create": dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.
问题分析: 默认情况下,docker 命令会使用 Unix socket 与 Docker 引擎通讯。而只有 root 用户和 docker 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑,一般 Linux 系统上不会直接使用 root 用户。因此,更好地做法是将需要使用 docker 的用户加入 docker 用户组。
1、创建docker组(安装docker时会自动创建,一般无需重新创建)
$ sudo groupadd docker
2、将当前用户加入到docker用户组
$ sudo gpasswd -a ${USER} docker
3 、重新启动docker
sudo service docker restart
#或者执行以下命令,无须重新登录
newgrp docker
4、测试docker命令是否可以使用sudo正常使用
docker ps
测试:
$ docker run --rm hello-world
结果:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
Status: Downloaded newer image for hello-world:latest
Hello from Docker!This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)
3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/
For more examples and ideas, visit: https://docs.docker.com/get-started/
默认情况下,docker 命令会使用 Unix socket 与 Docker 引擎通讯。而只有 root 用户和 docker 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑,一般 Linux 系统上不会直接使用 root 用户。因此,更好地做法是将需要使用 docker 的用户加入 docker 用户组。
1、创建docker组(安装docker时会自动创建,一般无需重新创建)
$ sudo groupadd docker
2、将当前用户加入到docker用户组
$ sudo gpasswd -a ${USER} docker
3 、重新启动docker
sudo service docker restart
#或者执行以下命令,无须重新登录
newgrp docker
4、测试docker命令是否可以使用sudo正常使用
docker ps
测试:
$ docker run --rm hello-world
结果:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
Status: Downloaded newer image for hello-world:latest
Hello from Docker!This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)
3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/
For more examples and ideas, visit: https://docs.docker.com/get-started/
删除安装包:
sudo apt-get purge docker-ce
删除镜像、容器、配置文件等内容:
sudo rm -rf /var/lib/docker
1. 停止docker服务:
sudo service docker stop
2. 修改docker.service配置文件,使用–graph 参数指定新的目录
$ sudo vi /lib/systemd/system/docker.service
在打开的文本里,找到ExecStart进行相应的修改:
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph="/home/xiaoyuanzi/python/Docker" --storage-driver=overlay
ExecReload=/bin/kill -s HUP $MAINPID
3. 重新加载配置文件
$ sudo systemctl daemon-reload
4. 启动docker,查看docker状态
$ sudo systemctl start docker
$ sudo systemctl enable docker
$ sudo systemctl status docker
5. 查看默认路径是否修改成功
$ sudo docker info
或者直接查看docker路径
sudo docker info | grep "Docker Root Dir"
结果:
其他方法: 未验证是否成功
https://blog.51cto.com/forangela/1949947
https://zhuanlan.zhihu.com/p/95533274
https://blog.csdn.net/BigData_Mining/article/details/104921479