阿里云服务器centos7 安装docker 和docker-compose 及相关命令

推荐用阿里云的容器服务

环境检测更新

环境检测

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

uname -r

#输出
3.10.0-862.14.4.el7.x86_64

更新

yum -y update

创建用户及用户组

useradd docker

设置用户密码

passwd docker

随后要输入2次密码

安装docker

执行自动安装命令

curl -fsSL https://get.docker.com/ | sh

执行

usermod -aG docker docker

启动

设置启动和开机启动

systemctl start docker
systemctl enable docker

切换到docker用户下

方式一

su docker

方式二

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

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

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

docker pull hello-world

运行容器

docker run hello-world

输出

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版本

docker  --version

docker-compose 安装

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

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

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

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 版本

docker-compose --version

docker 镜像加速器

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

清空所有镜像

方式一

docker rmi -f $(docker images -qa)

方式二

docker system prune --volumes
docker system prune -a

该命令清除:

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

强制删除

docker image rm -f IMAGE ID
案例
docker image rm -f bcb0d5f1f539

FAQ

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风.foxwho

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值