Docker:centos79-docker-compose安装记录

1.安装环境:centos7.9 x86

2.安装最新版:

复制代码
[root@localhost ~]# curl -fsSL get.docker.com -o get-docker.sh
[root@localhost ~]# sh get-docker.sh
# Executing docker install script, commit: e5543d473431b782227f8908005543bb4389b8de
+ sh -c 'yum install -y -q yum-utils'
+ sh -c 'yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo'
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
+ '[' stable '!=' stable ']'
+ sh -c 'yum makecache'
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                                                                                                    | 5.0 kB  00:00:00
 * base: mirrors.bfsu.edu.cn
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
base                                                                                                                                                                                    | 3.6 kB  00:00:00
docker-ce-stable                                                                                                                                                                        | 3.5 kB  00:00:00
extras                                                                                                                                                                                  | 2.9 kB  00:00:00
updates                                                                                                                                                                                 | 2.9 kB  00:00:00
(1/13): base/7/x86_64/filelists_db                                                                                                                                                      | 7.2 MB  00:00:00
(2/13): base/7/x86_64/other_db                                                                                                                                                          | 2.6 MB  00:00:00
(3/13): docker-ce-stable/7/x86_64/filelists_db                                                                                                                                          |  57 kB  00:00:01
(4/13): docker-ce-stable/7/x86_64/updateinfo                                                                                                                                            |   55 B  00:00:02
(5/13): docker-ce-stable/7/x86_64/primary_db                                                                                                                                            | 131 kB  00:00:01
(6/13): epel/x86_64/filelists_db                                                                                                                                                        |  12 MB  00:00:00
(7/13): epel/x86_64/prestodelta                                                                                                                                                         | 1.8 kB  00:00:00
(8/13): extras/7/x86_64/other_db                                                                                                                                                        | 150 kB  00:00:00
(9/13): extras/7/x86_64/filelists_db                                                                                                                                                    | 303 kB  00:00:00
(10/13): epel/x86_64/other_db                                                                                                                                                           | 3.4 MB  00:00:00
(11/13): updates/7/x86_64/other_db                                                                                                                                                      | 1.5 MB  00:00:00
(12/13): docker-ce-stable/7/x86_64/other_db                                                                                                                                             | 142 kB  00:00:01
(13/13): updates/7/x86_64/filelists_db                                                                                                                                                  |  14 MB  00:00:00
Metadata Cache Created
+ sh -c 'yum install -y -q docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin'
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-buildx-plugin-0.12.1-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for docker-buildx-plugin-0.12.1-1.el7.x86_64.rpm is not installed
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://download.docker.com/linux/centos/gpg

================================================================================

To run Docker as a non-privileged user, consider setting up the
Docker daemon in rootless mode for your user:

    dockerd-rootless-setuptool.sh install

Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.


To run the Docker daemon as a fully privileged service, but granting non-root
users access, refer to https://docs.docker.com/go/daemon-access/

WARNING: Access to the remote API on a privileged Docker daemon is equivalent
         to root access on the host. Refer to the 'Docker daemon attack surface'
         documentation for details: https://docs.docker.com/go/attack-surface/

================================================================================

[root@localhost ~]#

2.检查版本,测试程序

复制代码
[root@localhost ~]# docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[root@localhost ~]# docker -v
Docker version 25.0.2, build 29cf629
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:4bd78111b6914a99dbc560e6a20eab57ff6655aea4a80c50b0c5491968cbc2e6
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/

3.下载docker-compose:

chmod +x /usr/local/bin/docker-compose

复制代码
[root@localhost ~]# sudo curl -L https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 56.7M  100 56.7M    0     0  75758      0  0:13:05  0:13:05 --:--:--  478k
[root@localhost ~]# chmod +x /usr/local/bin/docker-compose
[root@localhost ~]# docker-compose --version
Docker Compose version v2.21.0
[root@localhost ~]# pip install docker-compose
-bash: pip: command not found

4.下载python

复制代码
[root@localhost ~]# yum install python
[root@localhost ~]# yum install python-pip
[root@localhost ~]# python
Python 2.7.5 (default, Nov 14 2023, 16:14:06)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@localhost ~]# pip -V
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)

5.编写docker-compose.yam文件

复制代码
version: "5"
services:
  db:
    image: postgres:9.4
    volumes:
      - db-data:/var/lib/postgresql/data
    networks:
      - backend
    deploy:
      placement:
        constraints: [node.role == manager]

networks:
  frontend:
  backend:

volumes:
  db-data:

[root@localhost dhome]# docker-compose -f docker-compose.yml up -d
[+] Running 13/15
 ⠏ db 14 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿] 49.44MB/53.62MB Pulling                                                                                                                                                 20.0s
   ✔ 619014d83c02 Pull complete                                                                                                                                                                           5.3s
   ✔ 7ec0fe6664f6 Pull complete                                                                                                                                                                           3.3s
   ✔ 9ca7ba8f7764 Pull complete                                                                                                                                                                           1.3s
   ✔ 9e1155d037e2 Pull complete                                                                                                                                                                           3.7s
   ✔ febcfb7f8870 Pull complete                                                                                                                                                                           7.1s
   ✔ 8c78c79412b5 Pull complete                                                                                                                                                                           5.5s
   ✔ 5a35744405c5 Pull complete                                                                                                                                                                           6.6s
   ✔ 27717922e067 Pull complete                                                                                                                                                                           6.8s
   ⠼ 36f0c5255550 Downloading     [==============================================>    ]  49.44MB/53.62MB                                                                                                 16.5s
   ✔ dbf0a396f422 Download complete                                                                                                                                                                       8.1s
   ✔ ec4c06ea33e5 Download complete                                                                                                                                                                       8.5s
   ✔ e8dd33eba6d1 Download complete                                                                                                                                                                       9.7s
   ✔ 51c81b3b2c20 Download complete                                                                                                                                                                       9.7s
   ✔ 2a03dd76f5d7 Download complete                                                                                                                                                                      11.0s
相关推荐
GlobalSign数字证书1 小时前
自动化时代,如何高效部署SSL证书?
运维·自动化·ssl
大侠锅锅3 小时前
第 19 篇:远程运维体系——指标、SSH、日志与 OTA 升级
运维·ssh
爱码少年5 小时前
Docker遍历镜像生成导出镜像命令六法
docker·shell
公众号:fuwuqiBMC5 小时前
(转自“服务器BMC”)服务器BMC芯片——多Die(芯片)封装
运维·服务器·人工智能
gs801406 小时前
【实战】记一次 Linux 服务器入侵排查:grok-agent 后门木马深度剖析与彻底清理
linux·运维·服务器
D2aZXN3FhrDa7e2127 小时前
佛山乐从低预算实体店如何选择?看美诚AI自动化获客方案
运维·人工智能·自动化·佛山美诚科技有限公司
BullSmall8 小时前
Sonarqube9.9 docker 镜像启动后 conf 下的配置文件没有了
docker·容器·eureka
无足鸟ICT8 小时前
【RHCA+】查看变量
linux·运维·服务器
ruofu338 小时前
wsl端是py312,但是项目是py311, 如何下载py311的依赖包(wheels)
python·docker
Kina_C8 小时前
Linux DNS 服务器-从高速缓存到辅助 DNS 部署指南
linux·运维·服务器·dns