Podman : Use Docker Compose2024/11/06 |
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. <<<< Sending build context to Docker daemon 3.472kB STEP 1/6: FROM fedora STEP 2/6: MAINTAINER ServerWorld <admin@srv.world> --> 09e660430cb7 STEP 3/6: RUN dnf -y install nginx ..... ..... ✓ Network root_default Created 0.0s ✓ Container root-db-1 Started 0.3s ✓ Container root-web-1 Started 0.3s[root@dlp ~]# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 97ee105b152d docker.io/library/root-web:latest /usr/sbin/nginx -... 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp, 80/tcp root-web-1 89fce851a278 docker.io/library/mariadb:latest mariadbd 3 minutes ago Up 3 minutes 0.0.0.0:3306->3306/tcp, 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 | 89fce851a278 | +---------------+--------------+[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 6 minutes ago Up 6 minutes 3306/tcp root-web-1 docker.io/library/root-web:latest "/usr/sbin/nginx -g " web 6 minutes ago Up 6 minutes 80/tcp # show logs of containers [root@dlp ~]# docker-compose logs db-1 | 2024-11-06 00:45:29+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.5.2+maria~ubu2404 started. db-1 | 2024-11-06 00:45:30+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' db-1 | 2024-11-06 00:45:30+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.5.2+maria~ubu2404 started. db-1 | 2024-11-06 00:45:30+00:00 [Note] [Entrypoint]: MariaDB upgrade not required db-1 | 2024-11-06 0:45:30 0 [Note] Starting MariaDB 11.5.2-MariaDB-ubu2404 source revision ea75a0b6009b0251e83193cd38c3974e36b65e06 server_uid TpZ76ucH4nV+AyKFiAG+J41iNaU= as process 1 ..... ..... db-1 | 2024-11-06 0:45:31 0 [Note] mariadbd: Event Scheduler: Loaded 0 events db-1 | 2024-11-06 0:45:31 0 [Note] mariadbd: ready for connections. db-1 | Version: '11.5.2-MariaDB-ubu2404' socket: '/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution # 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@89fce851a278:/# # 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 10 minutes ago Up 30 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 |
|