Podman : Use Docker Compose2025/11/12 |
|
To Install Docker Compose, it's easy to configure and run multiple containers as a Docker application. |
|
| [1] | |
| [2] | Install Docker Compose. |
|
[root@dlp ~]#
dnf -y install docker-compose
# start podman.socket [root@dlp ~]# systemctl enable --now podman.socket
|
| [3] | For example, Configure an application that has Web and DB services with Docker Compose. |
FROM fedora 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: fedora
MYSQL_PASSWORD: password
MYSQL_DATABASE: fedora_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
# buid and run [root@dlp ~]# docker-compose up -d Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. >>>> Executing external compose provider "/usr/libexec/docker/cli-plugins/docker-compose". Please see podman-compose(1) for how to disable this message. <<<< [+] Running 10/10 ..... ..... ✓ Service web Built 17.5s ✓ web Built 0.0s ✓ Network root_default Created 0.0s ✓ Container root-db-1 Started 0.2s ✓ Container root-web-1 Started[root@dlp ~]# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ce750080ff62 docker.io/library/root-web:latest /usr/sbin/nginx -... 11 seconds ago Up 12 seconds 0.0.0.0:80->80/tcp root-web-1 72d39d153039 docker.io/library/mariadb:latest mariadbd 11 seconds ago Up 12 seconds 0.0.0.0:3306->3306/tcp root-db-1 # verify accesses [root@dlp ~]# mariadb -h 127.0.0.1 -u root -p -e "show variables like 'hostname';" Enter password: +---------------+--------------+ | Variable_name | Value | +---------------+--------------+ | hostname | 72d39d153039 | +---------------+--------------+[root@dlp ~]# mariadb -h 127.0.0.1 -u fedora -p -e "show databases;" Enter password: +--------------------+ | Database | +--------------------+ | fedora_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 2 minutes ago Up 2 minutes 0.0.0.0:3306->3306/tcp root-web-1 docker.io/library/root-web:latest "/usr/sbin/nginx -g …" web 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp # show logs of containers [root@dlp ~]# docker-compose logs db-1 | 2025-11-12 00:28:38+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:12.0.2+maria~ubu2404 started. db-1 | 2025-11-12 00:28:39+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' db-1 | 2025-11-12 00:28:39+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:12.0.2+maria~ubu2404 started. db-1 | 2025-11-12 00:28:39+00:00 [Note] [Entrypoint]: Initializing database files db-1 | 2025-11-12 00:28:40+00:00 [Note] [Entrypoint]: Database files initialized db-1 | 2025-11-12 00:28:40+00:00 [Note] [Entrypoint]: Starting temporary server db-1 | 2025-11-12 00:28:40+00:00 [Note] [Entrypoint]: Waiting for server startup db-1 | 2025-11-12 0:28:40 0 [Note] Starting MariaDB 12.0.2-MariaDB-ubu2404 source revision aab83aecdca15738d114cf5a2f223f1d12e4e6bd server_uid bpSerjdIe/zrgGT05t9XEOz6y4s= as process 96 ..... ..... # 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
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
root@72d39d153039:/# exit
# stop application and also shutdown all containers [root@dlp ~]# docker-compose stop [+] Stopping 1/2 ✓ Container root-web-1 Stopped 0.2s Container root-db-1 Stopping 0.2s [+] Stopping 2/2eth1 (unregistering): left allmulticast mode ✓ Container root-web-1 Stopped 0.2s ✓ 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 1/1 ✓ Container root-web-1 Started 0.1s[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 4 minutes ago Up 5 seconds 0.0.0.0:80->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 Yes
[+] Removing 1/0e root-db-1 (y/N) y
✓ Container root-db-1 Removed 0.0s
|
| Sponsored Link |
|
|