Podman : Use Docker Compose2025/01/21 |
|
To Install Docker Compose, it's easy to configure and run multiple containers as a Docker application. |
|
| [1] | |
| [2] | Install Docker Compose. |
|
[root@dlp ~]#
curl -L https://github.com/docker/compose/releases/download/v2.32.4/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
[root@dlp ~]#
[root@dlp ~]# chmod 755 /usr/local/bin/docker-compose
docker-compose --version Docker Compose version v2.32.4 |
| [3] | For example, Configure an application that has Web and DB services with Docker Compose. |
FROM quay.io/centos/centos:stream10 LABEL Maintainer "ServerWorld <admin@srv.world>" RUN dnf -y install nginx EXPOSE 80 CMD ["/usr/sbin/nginx", "-g", "daemon off;"]
services:
db:
image: docker.io/library/mariadb
volumes:
- /var/lib/containers/disk01:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: cent
MYSQL_PASSWORD: password
MYSQL_DATABASE: cent_db
user: 0:0
privileged: true
ports:
- "3306:3306"
web:
build: .
ports:
- "80:80"
volumes:
- /var/lib/containers/disk02:/usr/share/nginx/html
privileged: true
# build and run [root@dlp ~]# docker-compose up -d [+] Building 1.7s (8/8) FINISHED docker-container:default ..... ..... [+] Running 3/3veth2: entered allmulticast mode ✓ web Built ✓ Container root-db-1 Started ✓ Container root-web-1 Started[root@dlp ~]# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7c8a1f172184 docker.io/moby/buildkit:buildx-stable-1 11 minutes ago Up 11 minutes buildx_buildkit_default ab2e8be97696 docker.io/library/root-web:latest /usr/sbin/nginx -... About a minute ago Up About a minute 0.0.0.0:80->80/tcp root-web-1 6ff448bfc445 docker.io/library/mariadb:latest mariadbd About a minute ago Up About a minute 0.0.0.0:3306->3306/tcp root-db-1 # verify accesses [root@dlp ~]# mysql -h 127.0.0.1 -u root -p -e "show variables like 'hostname';" Enter password: +---------------+--------------+ | Variable_name | Value | +---------------+--------------+ | hostname | 6ff448bfc445 | +---------------+--------------+[root@dlp ~]# mysql -h 127.0.0.1 -u cent -p -e "show databases;" Enter password: +--------------------+ | Database | +--------------------+ | cent_db | | information_schema | +--------------------+[root@dlp ~]# echo "Hello Docker Compose World" > /var/lib/containers/disk02/index.html [root@dlp ~]# curl 127.0.0.1 Hello Docker Compose World |
| [4] | Other basic operations of Docker Compose are follows. |
|
# verify state of containers [root@dlp ~]# docker-compose ps NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS root-db-1 docker.io/library/mariadb:latest "mariadbd" db 4 minutes ago Up 4 minutes 3306/tcp root-web-1 docker.io/library/root-web:latest "/usr/sbin/nginx -g …" web 4 minutes ago Up 4 minutes 80/tcp # show logs of containers [root@dlp ~]# docker-compose logs db-1 | 2025-01-21 07:28:12+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.6.2+maria~ubu2404 started. db-1 | 2025-01-21 07:28:12+00:00 [Warn] [Entrypoint]: /sys/fs/cgroup///memory.pressure not writable, functionality unavailable to MariaDB db-1 | 2025-01-21 07:28:12+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' db-1 | 2025-01-21 07:28:12+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.6.2+maria~ubu2404 started. db-1 | 2025-01-21 07:28:13+00:00 [Note] [Entrypoint]: MariaDB upgrade not required db-1 | 2025-01-21 7:28:13 0 [Note] Starting MariaDB 11.6.2-MariaDB-ubu2404 source revision d8dad8c3b54cd09fefce7bc3b9749f427eed9709 server_uid 60CBFwXHGr/2pUSMnsHtTvEIbr0= as process 1 ..... ..... # run any commands inside a container # container name is just the one set in [docker-compose.yml] [root@dlp ~]# docker-compose exec db /bin/bash
root@6ff448bfc445:/# exit
exit
# stop application and also shutdown all containers [root@dlp ~]# docker-compose stop
[+] Stopping 1/2
✓ Container root-web-1 Stopped
Container root-db-1 Stopping
[+] Stopping 2/2eth1 (unregistering): left allmulticast mode
✓ Container root-web-1 Stopped
✓ Container root-db-1 Stopped
# start a service alone in application # if set dependency, other container starts [root@dlp ~]# docker-compose up -d web
[+] Running 0/1
Container root-web-1 Recreate
[+] Running 1/1podman1: port 1(veth1) entered blocking state
✓ Container root-web-1 Started
[root@dlp ~]# docker-compose ps NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS root-web-1 docker.io/library/root-web:latest "/usr/sbin/nginx -g …" web 40 seconds ago Up 39 seconds 80/tcp # remove all containers in application # if a container is running, it won't be removed [root@dlp ~]# docker-compose rm
? Going to remove root-db-1 y
[+] Removing 1/1
✓ Container root-db-1 Removed
|
| Sponsored Link |
|
|