Centos中Docker安装方法
-
- 先删除旧的版本(如果没有可以跳过)
$ sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
- 安装必须的依赖:
$ sudo yum install -y yum-utils \ device-mapper-persistent-data \ lvm2
添加stable的Docker-ce的源:
$ sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
- 安装docker-ce:
$ sudo yum install docker-ce docker-ce-cli containerd.io
- 启动服务并测试一下:
# 启动服务 sudo systemctl start docker # 来一个Hello World吧 sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535 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已经成功安装并运行了了。
- 关于升级&删除:
升级:
# 更新所有 yum -y update # 更新指定 yum -y update docker-ce docker-ce-cli containerd.io
删除:
sudo yum remove docker-ce # 删除文件系统 sudo rm -rf /var/lib/docker
6.Docker-compose集合命令
Compose工具是一个批量工具,用于运行与管理多个docker容器。
官方文档:https://docs.docker.com/compose/install/# 下载docker-compose sudo curl -L "https://github.com/docker/compose/releases/download/1.28.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose # 国内镜像 sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.28.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose # 给予执行权限 sudo chmod +x /usr/local/bin/docker-compose # 测试命令 $ docker-compose --version docker-compose version 1.28.5, build 1110ad01