安装部署Docker-Compose

随笔记录

目录

1. 要在CentOS 7上安装Docker,操作如下:

1.1 更新系统

1.2 安装Docker依赖

1.3 添加Docker官方存储库

1.4 安装Docker引擎

1.5 启动Docker服务

1.6 验证Docker是否成功安装

1.7 设置Docker开机自启动

1.8 权限问题

 2. 安装Docker-compose

2.1 准备

2.1.1 系统设置

2.2 在 /usr/local/bin 目录下下载 Docker Compose 二进制文件

2.3 将下载的二进制文件设置为可执行权限

2.4 创建一个符号链接以便于直接使用 docker-compose 命令

2.5 验证安装是否成功

3. docker-compse 常用命令

3.1  启动服务

3.2 列出项目中所有容器

3.3 停止正在运行的容器

3.4 启动、重启 容器

3.5 停止和删除容器

3.7 查看服务容器的输出 

3.8 删除所有(停止状态的)服务容器


1. 要在CentOS 7上安装Docker,操作如下:

1.1 更新系统
# 创建dockers 文件夹
[root@localhost magx]# pwd
/home/magx
[root@localhost magx]# mkdir Dockers
[root@localhost magx]# cd /home/magx/Dockers# 查询yum version[root@localhost Dockers]# yum --version
3.4.3Installed: rpm-4.11.3-48.el7_9.x86_64 at 2023-04-21 10:31Built    : CentOS BuildSystem <http://bugs.centos.org> at 2021-11-24 16:33Committed: Michal Domonkos <mdomonko@redhat.com> at 2021-11-01Installed: yum-3.4.3-168.el7.centos.noarch at 2023-10-10 08:57Built    : CentOS BuildSystem <http://bugs.centos.org> at 2020-10-01 17:03Committed: CentOS Sources <bugs@centos.org> at 2020-09-29Installed: yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch at 2023-10-10 08:57Built    : CentOS BuildSystem <http://bugs.centos.org> at 2020-05-12 16:27Committed: Michal Domonkos <mdomonko@redhat.com> at 2020-03-12
[root@localhost Dockers]#
[root@localhost Dockers]## 升级系统
[root@localhost Dockers]# yum update
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.huaweicloud.com* epel: mirrors.bfsu.edu.cn* extras: mirrors.huaweicloud.com* updates: mirrors.huaweicloud.com
No packages marked for update
[root@localhost Dockers]#
1.2 安装Docker依赖
# 
# sudo  yum install -y yum-utils device-mapper-persistent-data lvm2[root@localhost Dockers]# yum install -y yum-utils device-mapper-persistent-data lvm2
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.huaweicloud.com* epel: mirrors.bfsu.edu.cn* extras: mirrors.huaweicloud.com* updates: mirrors.huaweicloud.com
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
Package device-mapper-persistent-data-0.8.5-3.el7_9.2.x86_64 already installed and latest version
Package 7:lvm2-2.02.187-6.el7_9.5.x86_64 already installed and latest version
Nothing to do
[root@localhost Dockers]#
1.3 添加Docker官方存储库
[root@localhost Dockers]#
[root@localhost Dockers]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
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                # 保存路径: /etc/yum.repos.d/
[root@localhost Dockers]#
[root@localhost Dockers]#
1.4 安装Docker引擎
[root@localhost Dockers]#
[root@localhost Dockers]# yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.huaweicloud.com* epel: mirrors.bfsu.edu.cn* extras: mirrors.huaweicloud.com* updates: mirrors.huaweicloud.com
docker-ce-stable                                                                                                                                  | 3.5 kB  00:00:00
(1/2): docker-ce-stable/7/x86_64/primary_db                                                                                                       | 118 kB  00:00:00
(2/2): docker-ce-stable/7/x86_64/updateinfo                                                                                                       |   55 B  00:00:01
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.6.25-3.1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.6.25-3.1.el7.x86_64
---> Package docker-ce.x86_64 3:24.0.7-1.el7 will be installed
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-24.0.7-1.el7.x86_64
---> Package docker-ce-cli.x86_64 1:24.0.7-1.el7 will be installed
--> Processing Dependency: docker-buildx-plugin for package: 1:docker-ce-cli-24.0.7-1.el7.x86_64
--> Processing Dependency: docker-compose-plugin for package: 1:docker-ce-cli-24.0.7-1.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
---> Package docker-buildx-plugin.x86_64 0:0.11.2-1.el7 will be installed
---> Package docker-ce-rootless-extras.x86_64 0:24.0.7-1.el7 will be installed
--> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-24.0.7-1.el7.x86_64
--> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-24.0.7-1.el7.x86_64
---> Package docker-compose-plugin.x86_64 0:2.21.0-1.el7 will be installed
--> Running transaction check
---> Package fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 will be installed
--> Processing Dependency: libfuse3.so.3(FUSE_3.2)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3(FUSE_3.0)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3()(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
---> Package slirp4netns.x86_64 0:0.4.3-4.el7_8 will be installed
--> Running transaction check
---> Package fuse3-libs.x86_64 0:3.6.1-4.el7 will be installed
--> Finished Dependency ResolutionDependencies Resolved=========================================================================================================================================================================Package                                        Arch                        Version                                          Repository                             Size
=========================================================================================================================================================================
Installing:containerd.io                                  x86_64                      1.6.25-3.1.el7                                   docker-ce-stable                       34 Mdocker-ce                                      x86_64                      3:24.0.7-1.el7                                   docker-ce-stable                       24 Mdocker-ce-cli                                  x86_64                      1:24.0.7-1.el7                                   docker-ce-stable                       13 M
Installing for dependencies:container-selinux                              noarch                      2:2.119.2-1.911c772.el7_8                        extras                                 40 kdocker-buildx-plugin                           x86_64                      0.11.2-1.el7                                     docker-ce-stable                       13 Mdocker-ce-rootless-extras                      x86_64                      24.0.7-1.el7                                     docker-ce-stable                      9.1 Mdocker-compose-plugin                          x86_64                      2.21.0-1.el7                                     docker-ce-stable                       13 Mfuse-overlayfs                                 x86_64                      0.7.2-6.el7_8                                    extras                                 54 kfuse3-libs                                     x86_64                      3.6.1-4.el7                                      extras                                 82 kslirp4netns                                    x86_64                      0.4.3-4.el7_8                                    extras                                 81 kTransaction Summary
=========================================================================================================================================================================
Install  3 Packages (+7 Dependent packages)Total download size: 107 M
Installed size: 378 M
Is this ok [y/d/N]: y                          # y
Downloading packages:
(1/10): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm                                                                                      |  40 kB  00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-buildx-plugin-0.11.2-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY01:09 ETA
Public key for docker-buildx-plugin-0.11.2-1.el7.x86_64.rpm is not installed
(2/10): docker-buildx-plugin-0.11.2-1.el7.x86_64.rpm                                                                                              |  13 MB  00:00:13
(3/10): docker-ce-24.0.7-1.el7.x86_64.rpm                                                                                                         |  24 MB  00:00:27
(4/10): docker-ce-cli-24.0.7-1.el7.x86_64.rpm                                                                                                     |  13 MB  00:00:15
(5/10): docker-ce-rootless-extras-24.0.7-1.el7.x86_64.rpm                                                                                         | 9.1 MB  00:00:09
(6/10): fuse3-libs-3.6.1-4.el7.x86_64.rpm                                                                                                         |  82 kB  00:00:00
(7/10): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm                                                                                                   |  54 kB  00:00:00
(8/10): slirp4netns-0.4.3-4.el7_8.x86_64.rpm                                                                                                      |  81 kB  00:00:00
(9/10): docker-compose-plugin-2.21.0-1.el7.x86_64.rpm                                                                                             |  13 MB  00:00:13
(10/10): containerd.io-1.6.25-3.1.el7.x86_64.rpm                                                                                                  |  34 MB  00:01:39
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                    1.1 MB/s | 107 MB  00:01:39
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:Userid     : "Docker Release (CE rpm) <docker@docker.com>"Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35From       : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y                # y
Running transaction check
Running transaction test
Transaction test succeeded
Running transactionInstalling : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                                                                   1/10Installing : containerd.io-1.6.25-3.1.el7.x86_64                                                                                                                  2/10Installing : docker-buildx-plugin-0.11.2-1.el7.x86_64                                                                                                             3/10Installing : fuse3-libs-3.6.1-4.el7.x86_64                                                                                                                        4/10Installing : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                                                                                  5/10Installing : slirp4netns-0.4.3-4.el7_8.x86_64                                                                                                                     6/10Installing : docker-compose-plugin-2.21.0-1.el7.x86_64                                                                                                            7/10Installing : 1:docker-ce-cli-24.0.7-1.el7.x86_64                                                                                                                  8/10Installing : docker-ce-rootless-extras-24.0.7-1.el7.x86_64                                                                                                        9/10Installing : 3:docker-ce-24.0.7-1.el7.x86_64                                                                                                                     10/10Verifying  : containerd.io-1.6.25-3.1.el7.x86_64                                                                                                                  1/10Verifying  : 3:docker-ce-24.0.7-1.el7.x86_64                                                                                                                      2/10Verifying  : docker-ce-rootless-extras-24.0.7-1.el7.x86_64                                                                                                        3/10Verifying  : docker-compose-plugin-2.21.0-1.el7.x86_64                                                                                                            4/10Verifying  : slirp4netns-0.4.3-4.el7_8.x86_64                                                                                                                     5/10Verifying  : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                                                                   6/10Verifying  : 1:docker-ce-cli-24.0.7-1.el7.x86_64                                                                                                                  7/10Verifying  : fuse3-libs-3.6.1-4.el7.x86_64                                                                                                                        8/10Verifying  : docker-buildx-plugin-0.11.2-1.el7.x86_64                                                                                                             9/10Verifying  : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                                                                                 10/10Installed:containerd.io.x86_64 0:1.6.25-3.1.el7                     docker-ce.x86_64 3:24.0.7-1.el7                     docker-ce-cli.x86_64 1:24.0.7-1.el7Dependency Installed:container-selinux.noarch 2:2.119.2-1.911c772.el7_8         docker-buildx-plugin.x86_64 0:0.11.2-1.el7         docker-ce-rootless-extras.x86_64 0:24.0.7-1.el7docker-compose-plugin.x86_64 0:2.21.0-1.el7                fuse-overlayfs.x86_64 0:0.7.2-6.el7_8              fuse3-libs.x86_64 0:3.6.1-4.el7slirp4netns.x86_64 0:0.4.3-4.el7_8Complete!
[root@localhost Dockers]# 
# 安装完成后,检查docker 文件夹[root@localhost Dockers]# ll
total 0
-rw-r--r--. 1 root root 0 Dec  4 10:21 =
-rw-r--r--. 1 root root 0 Dec  4 10:21 Finished
-rw-r--r--. 1 root root 0 Dec  4 10:21 Package
-rw-r--r--. 1 root root 0 Dec  4 10:21 Processing
-rw-r--r--. 1 root root 0 Dec  4 10:21 Running
[root@localhost Dockers]#
[root@localhost Dockers]#

1.5 启动Docker服务
 # 启动docker
[root@localhost Dockers]#
[root@localhost Dockers]# systemctl start docker          # 查看docker服务 是否运行
[root@localhost Dockers]#
[root@localhost Dockers]# ps -aux|grep docker*
root     104955  5.0  0.1 3500780 63228 ?       Ssl  10:23   0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root     105245  0.0  0.0 112812   992 pts/4    S+   10:24   0:00 grep --color=auto docker*
[root@localhost Dockers]##  停止 docker服务
[root@localhost Dockers]# systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:docker.socket
[root@localhost Dockers]## 查看docker服务 是否停止运行
[root@localhost Dockers]# ps -aux|grep docker*
root     105646  0.0  0.0 112812   992 pts/4    S+   10:25   0:00 grep --color=auto docker*
[root@localhost Dockers]#
1.6 验证Docker是否成功安装
# sudo docker run hello-world# docker服务 已运行
[root@localhost Dockers]# ps -aux|grep docker*
root     108747  2.8  0.2 3459032 67708 ?       Ssl  10:31   0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root     109224  0.0  0.0 112812   992 pts/4    S+   10:31   0:00 grep --color=auto docker*
[root@localhost Dockers]## 验证Docker 是否安装成功
# 如果一切顺利,将看到一个测试容器成功运行的消息[root@localhost Dockers]#
[root@localhost Dockers]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete
Digest: sha256:c79d06dfdfd3d3eb04cafd0dc2bacab0992ebc243e083cabe208bac4dd7759e0
Status: Downloaded newer image for hello-world:latestHello 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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare 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/[root@localhost Dockers]#
1.7 设置Docker开机自启动
# 设置开机自启动Docker服务
# sudo systemctl enable docker[root@localhost Dockers]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost Dockers]#
[root@localhost Dockers]#
1.8 权限问题

现在,你已经成功在CentOS 7上安装了Docker。你可以使用docker命令来管理和运行容器了。 请注意,执行Docker命令可能需要使用sudo来获取足够的权限。如果你想允许普通用户执行Docker命令,你可以将该用户添加到docker用户组中

Note: 设置完成后,请注销并重新登录以使更改生效

# sudo usermod -aG docker your_username[root@localhost Dockers]# usermod -ag docker magx    # -aG 失误错写成 -ag
usermod: -a flag is only allowed with the -G flag
Usage: usermod [options] LOGINOptions:-c, --comment COMMENT         new value of the GECOS field-d, --home HOME_DIR           new home directory for the user account-e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE-f, --inactive INACTIVE       set password inactive after expirationto INACTIVE-g, --gid GROUP               force use GROUP as new primary group-G, --groups GROUPS           new list of supplementary GROUPS-a, --append                  append the user to the supplemental GROUPSmentioned by the -G option without removingthe user from other groups-h, --help                    display this help message and exit-l, --login NEW_LOGIN         new value of the login name-L, --lock                    lock the user account-m, --move-home               move contents of the home directory to thenew location (use only with -d)-o, --non-unique              allow using duplicate (non-unique) UID-p, --password PASSWORD       use encrypted password for the new password-R, --root CHROOT_DIR         directory to chroot into-P, --prefix PREFIX_DIR       prefix directory where are located the /etc/* files-s, --shell SHELL             new login shell for the user account-u, --uid UID                 new UID for the user account-U, --unlock                  unlock the user account-v, --add-subuids FIRST-LAST  add range of subordinate uids-V, --del-subuids FIRST-LAST  remove range of subordinate uids-w, --add-subgids FIRST-LAST  add range of subordinate gids-W, --del-subgids FIRST-LAST  remove range of subordinate gids-Z, --selinux-user SEUSER     new SELinux user mapping for the user account[root@localhost Dockers]#
[root@localhost Dockers]# usermod -aG docker magx
[root@localhost Dockers]#Note: 请注销并重新登录以使更改生效

 2. 安装Docker-compose

Docker-Compose是基于Docker的编排工具,需要有Docker环境 

1、Docker-Compose只能管理当前计算机上的 Docker容器,不能跨计算机管理Docker容器;

2、一个项目可以包括多个容器实例,但Docker-Compose无法实现多容器间负载均衡,若要实现此功能,则需要借助诸如Nginx等工具。

2.1 准备
2.1.1 系统设置

设置允许数据包转发

注意

Linux默认不允许数据包转发,此时执行docker run时出现如下警告,将导致无法远程访问该docker容器
...省略...
WARNING: IPv4 forwarding is disabled. Networking will not work.  

# 设置允许数据包转发# cat >> /usr/lib/sysctl.d/50-default.conf << EOF
net.ipv4.ip_forward = 1
EOF
# cat /usr/lib/sysctl.d/50-default.conf
# systemctl restart network1. # 设置允许数据包转发前 查看  /usr/lib/sysctl.d/50-default.conf [root@localhost Dockers]#
[root@localhost Dockers]# cat /usr/lib/sysctl.d/50-default.conf
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.# See sysctl.d(5) and core(5) for for documentation.# To override settings in this file, create a local file in /etc
# (e.g. /etc/sysctl.d/90-override.conf), and put any assignments
# there.# System Request functionality of the kernel (SYNC)
#
# Use kernel.sysrq = 1 to allow all keys.
# See http://fedoraproject.org/wiki/QA/Sysrq for a list of values and keys.
kernel.sysrq = 16# Append the PID to the core filename
kernel.core_uses_pid = 1# https://bugzilla.redhat.com/show_bug.cgi?id=1689344
kernel.kptr_restrict = 1# Source route verification
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0# Promote secondary addresses when the primary address is removed
net.ipv4.conf.default.promote_secondaries = 1
net.ipv4.conf.all.promote_secondaries = 1# Enable hard and soft link protection
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
[root@localhost Dockers]#2. 将net.ipv4.ip_forward=1 追加写入 /usr/lib/sysctl.d/50-default.conf [root@localhost Dockers]# cat >> /usr/lib/sysctl.d/50-default.conf << EOF
> net.ipv4.ip_forward=1
> EOF
[root@localhost Dockers]#3.设置允许数据包转发后 查看  /usr/lib/sysctl.d/50-default.conf 
# cat /usr/lib/sysctl.d/50-default.conf [root@localhost Dockers]# cat /usr/lib/sysctl.d/50-default.conf
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.# See sysctl.d(5) and core(5) for for documentation.# To override settings in this file, create a local file in /etc
# (e.g. /etc/sysctl.d/90-override.conf), and put any assignments
# there.# System Request functionality of the kernel (SYNC)
#
# Use kernel.sysrq = 1 to allow all keys.
# See http://fedoraproject.org/wiki/QA/Sysrq for a list of values and keys.
kernel.sysrq = 16# Append the PID to the core filename
kernel.core_uses_pid = 1# https://bugzilla.redhat.com/show_bug.cgi?id=1689344
kernel.kptr_restrict = 1# Source route verification
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0# Promote secondary addresses when the primary address is removed
net.ipv4.conf.default.promote_secondaries = 1
net.ipv4.conf.all.promote_secondaries = 1# Enable hard and soft link protection
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
net.ipv4.ip_forward=1               #追加写入
[root@localhost Dockers]#4. 重启网卡
# systemctl restart network[root@localhost Dockers]# systemctl restart network
[root@localhost Dockers]#

2.2 在 /usr/local/bin 目录下下载 Docker Compose 二进制文件
# sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose[root@localhost Dockers]# cd /usr/local/bin/
[root@localhost bin]#
[root@localhost bin]# ll
total 0
[root@localhost bin]# pwd
/usr/local/bin
[root@localhost bin]#
[root@localhost bin]# curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     00     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
100 56.9M  100 56.9M    0     0  54375      0  0:18:17  0:18:17 --:--:-- 53536
[root@localhost bin]#
2.3 将下载的二进制文件设置为可执行权限
[root@localhost bin]# ll
total 58304
-rw-r--r--. 1 root root 59699273 Dec  4 11:28 docker-compose
[root@localhost bin]#
[root@localhost bin]# chmod +x /usr/local/bin/docker-compose    # 添加可执行权限
[root@localhost bin]#
[root@localhost bin]# ll
total 58304
-rwxr-xr-x. 1 root root 59699273 Dec  4 11:28 docker-compose
[root@localhost bin]#
[root@localhost bin]#
2.4 创建一个符号链接以便于直接使用 docker-compose 命令
[root@localhost bin]#
[root@localhost bin]# ln -s /usr/local/bin/docker-compose  /usr/bin/docker-compose
[root@localhost bin]#
2.5 验证安装是否成功
# 验证docker-compose 是否安装成功[root@localhost bin]# docker-compose --version
Docker Compose version v2.23.3
[root@localhost bin]#

3. docker-compse 常用命令

3.1  启动服务
启动服务
# docker-compose up【选项】
-d 在后台运行服务容器;-f 指定使用的Compose模板文件,默认为docker-compose.yml,可以多次指定;
3.2 列出项目中所有容器
列出项目中所有容器
# docker-compose ps
3.3 停止正在运行的容器
停止正在运行的容器
# docker-compose stop
3.4 启动、重启 容器
启动容器
# docker-compose start重启项目中的服务
# docker-compose restart
3.5 停止和删除容器
停止和删除容器、网络、卷、镜像;
# docker-compose down[选项]
–rmi type:删除镜像,type必须为all或local:all,删除compose文件中定义的所有镜像;local,删除镜像名为空的镜像;
-v, –volumes:删除已经在compose文件中定义的和匿名的附在容器上的数据卷;
3.7 查看服务容器的输出 
# 查看服务容器的输出
# docker-compose logs
3.8 删除所有(停止状态的)服务容器
# 删除所有(停止状态的)服务容器:
# docker-compose rm[选项]
–f:强制直接删除,包括非停止状态的容器;-v:删除容器所挂载的数据卷;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/198566.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

品牌保护与知识产权:跨境电商中的法律挑战与解决方案

随着跨境电商的蓬勃发展&#xff0c;品牌保护和知识产权问题日益成为业界关注的焦点。在全球范围内进行电商业务&#xff0c;涉及到多国法律法规的复杂性&#xff0c;品牌所有者需要面对一系列法律挑战&#xff0c;保护其品牌和知识产权不受侵害。本文将深入探讨跨境电商中面临…

2023年广东工业大学腾讯杯新生程序设计竞赛不知道叫什么名字(前缀和)

需要的是男生女生数量相同&#xff0c;做个转化&#xff0c;女生变成-1&#xff0c;然后求一遍前缀和&#xff0c;我们希望找到最长的满足 s u m ( l , r ) 0 sum(l, r)0 sum(l,r)0的区间也就是 s u m ( r ) − s ( l − 1 ) 0 sum(r) - s(l - 1) 0 sum(r)−s(l−1)0 考虑枚…

L1-016:查验身份证

题目描述 一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下&#xff1a; 首先对前17位数字加权求和&#xff0c;权重分配为&#xff1a;{7&#xff0c;9&#xff0c;10&#xff0c;5&#xff0c;8&#xff0c;4&#xff0c;2&#xf…

quickapp_快应用_系统接口应用

系统接口 在项目中使用到的接口都需要在配置文件manifest.json中声明&#xff0c;不然会报如下警告 [WARN] 请在 manifest.json 文件里声明项目代码中用到的接口: system.storage, service.account, system.package, system.webview[1]检查某app是否在手机上安装 官方文档&a…

前端nginx代理,访问后端接口502问题积锦

项目场景&#xff1a; 项目上线&#xff1a;前端服务器配置了nginx反向代理后&#xff0c;用户发出请求&#xff0c;结果502&#xff0c;本地请求后端服务的时候就正常 解决方案 http状态码502 目前&#xff1a; 前端服务是正常的后端服务也正常那么&#xff0c;就是连结前…

【Flink基础】-- 延迟数据的处理

目录 ​一、关于延迟的一些概念 1、什么是延迟? 2、什么导致互联网延迟?

jenkins清理僵尸任务和排队任务

步骤 进入 Manage Jenkins系统管理 然后点击 Script Console , 然后根据自己需求选择性执行后面的脚本 查看所有进程 Thread.getAllStackTraces().keySet().each() {t -> println("name:"t.getName()) }例如: name:Thread-90 name:Scheduler-174573182-1 name…

Java List、Set、Map 之间的区别是什么?

Java List、Set、Map 之间的区别是什么&#xff1f; 在Java中&#xff0c;List、Set 和 Map 是三种不同的集合接口&#xff0c;用于存储和操作不同类型的数据。 1. List 接口&#xff1a; 特点&#xff1a; 有序&#xff1a;元素的顺序与插入顺序一致。允许重复&#xff1a;…

P1 Orange Pi Zero2镜像烧录和环境搭建(换源)

目录 前言 01 镜像下载 02 镜像烧录 03 SD卡启动 04 SSH登录开发板 05 基于官方外设开发 方法1 方法2 前言 此专栏为智能家居项目&#xff0c;使用的开发板一共有三块&#xff0c;分别为 主控&#xff1a;Orange Pi Zero2触摸屏控制面板&#xff1a;i.MX 6ULL子系统&…

【华为OD题库-063】字符匹配-java

题目 给你一个字符串数组(每个字符串均由小写字母组成)和一个字符规律&#xff08;由小写字母和.和组成)&#xff0c;识别数组中哪些字符串可以匹配到字符规律上。".“匹配任意单个字符&#xff0c;”*"匹配零个或多个前面的那一个元素&#xff0c;所谓匹配&#xff…

字符指针变量数组指针变量

字符指针变量 在指针的类型中&#xff0c;我们知道有一种指针叫做字符指针 一般的使用情况如下&#xff1a; #include<stdio.h> int main() {char ch w;char* pa &ch;*pa h;printf("%c", *pa);return 0; } 还有一种使用方法如下&#xff1a; #incl…

国内 AI 成图第一案!你来你会怎么判?

我国目前并未出台专门针对网络爬虫技术的法律规范&#xff0c;但在司法实践中&#xff0c;相关判决已屡见不鲜&#xff0c;K 哥特设了“K哥爬虫普法”专栏&#xff0c;本栏目通过对真实案例的分析&#xff0c;旨在提高广大爬虫工程师的法律意识&#xff0c;知晓如何合法合规利用…

室内外融合便携式定位终端5G+UWB+RTK

一、介绍 便携式定位终端主要用于提供高精度的位置数据&#xff0c;支持室内UWB定位和室外北斗系统定位功能&#xff0c;支持5G公网和5G专网通信功能&#xff0c;便携式定位终端中超宽带(UWB)和实时动态(RTK)技术的集成代表了精确位置跟踪方面的重大进步。这款UWBRTK便携式定位…

git 本地改动无法删除

1. 问题 记录下git遇到奇怪的问题&#xff0c;本地有些改动不知道什么原因无法删除 git stash&#xff0c; git reset --hard HEAD 等都无法生效&#xff0c;最终通过强制拉取线上解决 如下图&#xff1a; 2. 解决 git fetch --all git reset --hard origin/master执行这两…

Android RatingBar实现五星好评

属性 isIndicatorRatingBar 是否为指示器&#xff0c;为true时&#xff0c;用户将无法交互操作&#xff0c;默认为false。 numStars 显示的星型数量&#xff0c;必须是一个整形值&#xff0c;像“50”&#xff0c;虽然可以设置很大&#xff0c;但一般…

Java拆分集合

在对数据进行批量操作的时候&#xff0c;由于数据量太大&#xff0c;需要对数据进行拆分操作&#xff0c;分成N个小集合。 代码如下&#xff1a; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil;import java.util.ArrayList; import java.u…

java多线程学习- 下

六. 线程管理 6.1 线程组 类似于在计算机中使用文件夹管理文件, 也可以使用线程组来管理线程,在线程组中定义一组相似(相关)的线程. 在线程组中也可以定义子线程组, Thread 类有几个构造方法允许在创建线程时指定线程组,如果创建线程时没有指定线程组则该线程就属于浮现出所在…

STM32-新建工程(标准库)

目录 STM32F10x新建工程&#xff08;标准库&#xff09; 移植文件夹 新建工程 添加启动文件和必需文件 在工程中加载新添加的文件 在工程中添加文件路径 在工程中添加main函数 添加lib库 添加必需文件 添加宏定义 STM32F10x新建工程&#xff08;标准库&#xff09; …

【Python】创建简单的Python微服务Demo与FastAPI

创建简单的Python微服务Demo与FastAPI 在微服务架构中&#xff0c;通过FastAPI框架创建一个简单的Python微服务Demo涉及多个步骤&#xff0c;包括定义服务、使用框架、进行通信等。在这篇文章中&#xff0c;我们将使用FastAPI框架创建两个简单的微服务&#xff0c;它们通过RES…

HBase安装配置:一键自动安装配置

使用shell脚本一键下载、安装、配置HBase&#xff08;单机版&#xff09; 1. 把下面的脚本复制保存为/tmp/install_hbase.sh文件 #!/bin/bash# 安装之前确保安装目录有写入权限&#xff0c;若没有&#xff0c;自行增加 # 安装版本 zk_version"2.4.8" # 安装目录 zk…