我是靠谱客的博主 发嗲老虎,这篇文章主要介绍阿里云服务器centos7 安装docker 和docker-compose 及相关命令环境检测更新更新创建用户及用户组安装docker启动切换到docker用户下下载和运行hello-world镜像容器docker版本docker-compose 安装docker-compose 版本docker 镜像加速器清空所有镜像FAQ,现在分享给大家,希望可以做个参考。

推荐用阿里云的容器服务

环境检测更新

环境检测

Docker 要求 CentOS 系统的内核版本高于 3.10

复制代码
1
2
3
4
uname -r #输出 3.10.0-862.14.4.el7.x86_64

更新

复制代码
1
2
yum -y update

创建用户及用户组

复制代码
1
2
useradd docker

设置用户密码

复制代码
1
2
passwd docker

随后要输入2次密码

安装docker

执行自动安装命令

复制代码
1
2
curl -fsSL https://get.docker.com/ | sh

执行

复制代码
1
2
usermod -aG docker docker

启动

设置启动和开机启动

复制代码
1
2
3
systemctl start docker systemctl enable docker

切换到docker用户下

方式一

复制代码
1
2
su docker

方式二

退出root用户,使用docker用户登录

下载和运行hello-world镜像容器

要在 docker 用户下操作,不能在 root 用户下操作
下载镜像

复制代码
1
2
docker pull hello-world

运行容器

复制代码
1
2
docker run hello-world

输出

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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版本

复制代码
1
2
3
docker --version

docker-compose 安装

官方文档
https://docs.docker.com/compose/
源码地址
https://github.com/docker/compose

最新正式版
https://github.com/docker/compose/releases/latest

打开如上地址后,有如下安装地址,直接复制到终端进行安装

复制代码
1
2
3
curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose

docker-compose 版本

复制代码
1
2
docker-compose --version

docker 镜像加速器

https://blog.csdn.net/fenglailea/article/details/84301839

清空所有镜像

方式一

复制代码
1
2
docker rmi -f $(docker images -qa)

方式二

复制代码
1
2
3
docker system prune --volumes docker system prune -a

该命令清除:

  • 所有停止的容器
  • 所有不被任何一个容器使用的网络
  • 所有不被任何一个容器使用的volume
  • 所有无实例的镜像
    https://blog.csdn.net/weixin_42189048/article/details/106530444

强制删除

复制代码
1
2
3
4
docker image rm -f IMAGE ID 案例 docker image rm -f bcb0d5f1f539

FAQ

最后

以上就是发嗲老虎最近收集整理的关于阿里云服务器centos7 安装docker 和docker-compose 及相关命令环境检测更新更新创建用户及用户组安装docker启动切换到docker用户下下载和运行hello-world镜像容器docker版本docker-compose 安装docker-compose 版本docker 镜像加速器清空所有镜像FAQ的全部内容,更多相关阿里云服务器centos7内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部