Ubuntu 22.04
Sponsored Link

Podman : Use Docker Compose2022/04/28

 
To Install Docker Compose, it's easy to configure and run multiple containers as a Docker application.
Docker Compose is supported on Podman 3.0 or later.
[1]
[2] Install Docker Compose.
root@dlp:~#
curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
root@dlp:~#
chmod 755 /usr/local/bin/docker-compose
root@dlp:~#
docker-compose --version

docker-compose version 1.29.2, build 5becea4c
root@dlp:~#
podman version

Version:      3.4.4
API Version:  3.4.4
Go Version:   go1.17.3
Built:        Thu Jan  1 00:00:00 1970
OS/Arch:      linux/amd64
[3] For example, Configure an application that has Web and DB services with Docker Compose.
# start podman.socket

root@dlp:~#
systemctl start podman.socket
# define Web service container

root@dlp:~#
vi Dockerfile
FROM ubuntu
MAINTAINER ServerWorld <admin@srv.world>

RUN apt-get update
RUN apt-get -y install nginx
RUN echo "Compose Test on Nginx" > /var/www/html/index.html

EXPOSE 80
CMD ["/usr/sbin/nginx", "-g", "daemon off;"]

# define application configuration

root@dlp:~#
vi docker-compose.yml
version: '3'
services:
  db:
    image: docker.io/library/mariadb
    volumes:
      - /var/lib/containers/disk01:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_USER: ubuntu
      MYSQL_PASSWORD: password
      MYSQL_DATABASE: ubuntu_db
    ports:
      - "3306:3306"
  web:
    build: .
    ports:
      - "80:80"
    volumes:
      - /var/lib/containers/disk02:/usr/share/nginx/html

# build and run

root@dlp:~#
docker-compose up -d

Creating network "root_default" with the default driver
Building web
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
STEP 1/7: FROM ubuntu
STEP 2/7: MAINTAINER ServerWorld <admin@srv.world>
--> Using cache b51cc134aaf4cc8417d597b728187776ae8e480ae9a5231f662df47aae099735
--> b51cc134aaf
STEP 3/7: RUN apt-get update
.....
.....
Creating root_web_1 ... done
Creating root_db_1  ... done

root@dlp:~#
podman ps

CONTAINER ID  IMAGE                             COMMAND               CREATED             STATUS                 PORTS                   NAMES
337ca00a77c6  localhost/root_web:latest         /usr/sbin/nginx -...  About a minute ago  Up About a minute ago  0.0.0.0:80->80/tcp      root_web_1
d2b9f660161d  docker.io/library/mariadb:latest  mariadbd              About a minute ago  Up About a minute ago  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      | d2b9f660161d |
+---------------+--------------+

root@dlp:~#
mysql -h 127.0.0.1 -u ubuntu -p -e "show databases;"

Enter password:
+--------------------+
| Database           |
+--------------------+
| information_schema |
| ubuntu_db          |
+--------------------+

root@dlp:~#
curl 127.0.0.1

Compose Test on Nginx
[4] Other basic operations of Docker Compose are follows.
# verify state of containers

root@dlp:~#
docker-compose ps

   Name                 Command               State        Ports
---------------------------------------------------------------------
root_db_1    docker-entrypoint.sh mariadbd    Up      :3306->3306/tcp
root_web_1   /usr/sbin/nginx -g daemon off;   Up      :80->80/tcp

# show logs of containers

root@dlp:~#
docker-compose logs

Attaching to root_web_1, root_db_1
db_1   | 2022-04-28 06:47:01+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.7.3+maria~focal started.
db_1   | 2022-04-28 06:47:01+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1   | 2022-04-28 06:47:01+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.7.3+maria~focal started.
db_1   | 2022-04-28 06:47:01+00:00 [Note] [Entrypoint]: Initializing database files
.....
.....
db_1   | 2022-04-28  6:47:11 0 [Note] Server socket created on IP: '::'.
db_1   | 2022-04-28  6:47:11 0 [Note] mariadbd: ready for connections.
db_1   | Version: '10.7.3-MariaDB-1:10.7.3+maria~focal'  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@d2b9f660161d:/#

# stop application and also shutdown all containers

root@dlp:~#
docker-compose stop

Stopping root_web_1 ... done
Stopping root_db_1  ... done

# start a service alone in application
# if set dependency, other container starts

root@dlp:~#
docker-compose up -d web

Starting root_web_1 ... done
root@dlp:~#
docker-compose ps

   Name                 Command               State         Ports
----------------------------------------------------------------------
root_db_1    docker-entrypoint.sh mariadbd    Exit 0   :3306->3306/tcp
root_web_1   /usr/sbin/nginx -g daemon off;   Up       :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
Are you sure? [yN] y
Removing root_db_1 ... done
Matched Content