Docker / PODMAN in linux

First installed podman-compose then created docker file with name docker-compose.yml :

version: '3.1'

services:

  wordpress:
    image: wordpress1
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: mydbuser
      WORDPRESS_DB_PASSWORD: mydbpassword
      WORDPRESS_DB_NAME: mydb
    volumes:
      - wordpress:/var/www/html
      - logs:/var/log/apache2

  db:
    image: wordpress1db
    restart: always
    environment:
      MYSQL_DATABASE: mydb
      MYSQL_USER: mydbuser
      MYSQL_PASSWORD: mydbpassword
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

volumes:
  wordpress:
  db:
  logs:

now run :

podman-compose up -d

It will create containers and run webserver at 8080 port.

to stop and remove the containers run

podman-compose down

The docker file will create containers for webserver from image wordpress1 and container for database server from image wordpress1db, please check and update image name incase of any problem. Also you can commit after any change to webserver / mysql configuration to create another image locally.

The running containers will share storage outside the docker for mysql database files(/var/lib/mysql) in named space db and website (/var/www/html) at named space wordpress. These named spaces can be looked by running:

# podman volume ls

DRIVER      VOLUME NAME
local       fcab36796140245f735851f808b193c38e4771143db12ead1c59ce2b5fa3177e
local       WordPress_db
local       WordPress_logs
local       WordPress_wordpress

now run following to find out the actual location of the volumes

# podman volume inspect WordPress_db WordPress_wordpress
[
    {
        "Name": "WordPress_db",
        "Driver": "local",
        "Mountpoint": "/var/lib/containers/storage/volumes/WordPress_db/_data",
        "CreatedAt": "2022-01-31T18:54:23.157971622+05:30",
        "Labels": {
            "io.podman.compose.project": "WordPress"
        },
        "Scope": "local",
        "Options": {}
    },
    {
        "Name": "WordPress_wordpress",
        "Driver": "local",
        "Mountpoint": "/var/lib/containers/storage/volumes/WordPress_wordpress/_data",
        "CreatedAt": "2022-01-31T18:54:19.661705064+05:30",
        "Labels": {
            "io.podman.compose.project": "WordPress"
        },
        "Scope": "local",
        "Options": {}
    }
]

You can add/modify webserver files located at /var/lib/containers/storage/volumes/WordPress_wordpress/_data

To login to any of the containers above first findout the names of containers by running

]# podman container ls
CONTAINER ID  IMAGE                   COMMAND               CREATED      STATUS          PORTS                                        NAMES
4f7976ee3529  k8s.gcr.io/pause:3.5                          4 hours ago  Up 4 hours ago  0.0.0.0:8080->80/tcp  bca02e003722-infra
171df0e7c268  localhost/wp1:latest    apache2-foregroun...  4 hours ago  Up 4 hours ago  0.0.0.0:8080->80/tcp  WordPress_wordpress_1
70c70112d52b  localhost/wp1db:latest  mysqld                4 hours ago  Up 4 hours ago  0.0.0.0:8080->80/tcp  WordPress_db_1

the last word in each line is the name i.e. WordPress_wordpress_1 and WordPress_db_1 are the container names. Now to login to wordpress (webserver) type the following

# podman exec -ti WordPress_wordpress_1 /bin/bash
root@171df0e7c268:/var/www/html#

similarly for the db server type:

podman exec -ti WordPress_db_1 /bin/bash
root@70c70112d52b:/#

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.