Podman : Use Docker Compose2025/04/25 |
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
|
[3] | For example, Configure an application that has Web and DB services with Docker Compose. |
FROM fedora 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 e6353c10718a docker.io/library/mariadb:latest mariadbd About a minute ago Up About a minute 0.0.0.0:3306->3306/tcp root-db-1 335faaa85bc1 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 # verify accesses [root@dlp ~]# mysql -h 127.0.0.1 -u root -p -e "show variables like 'hostname';" Enter password: +---------------+--------------+ | Variable_name | Value | +---------------+--------------+ | hostname | e6353c10718a | +---------------+--------------+[root@dlp ~]# mysql -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 3 minutes ago Up 3 minutes 3306/tcp root-web-1 docker.io/library/root-web:latest "/usr/sbin/nginx -g …" web 3 minutes ago Up 3 minutes 80/tcp # show logs of containers [root@dlp ~]# docker-compose logs db-1 | 2025-04-25 05:33:04+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.7.2+maria~ubu2404 started. db-1 | 2025-04-25 05:33:04+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' db-1 | 2025-04-25 05:33:04+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.7.2+maria~ubu2404 started. db-1 | 2025-04-25 05:33:05+00:00 [Note] [Entrypoint]: Initializing database files db-1 | 2025-04-25 05:33:06+00:00 [Note] [Entrypoint]: Database files initialized db-1 | 2025-04-25 05:33:06+00:00 [Note] [Entrypoint]: Starting temporary server db-1 | 2025-04-25 05:33:06+00:00 [Note] [Entrypoint]: Waiting for server startup ..... ..... # 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@e6353c10718a:/# 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 6 minutes ago Up 4 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 Yes
[+] Removing 1/0e root-db-1 (y/N) y
✓ Container root-db-1 Removed 0.0s
|
Sponsored Link |
|