Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fedora - Manage containers with Podman Compose

#1
Manage containers with Podman Compose

Containers are awesome, allowing you to package your application along with its dependencies and run it anywhere. Starting with Docker in 2013, containers have been making the lives of software developers much easier.

One of the downsides of Docker is it has a central daemon that runs as the root user, and this has security implications. But this is where Podman comes in handy. Podman is a daemonless container engine for developing, managing, and running OCI Containers on your Linux system in root or rootless mode.

There are other articles on Fedora Magazine you can use to learn more about Podman. Two examples follow:

If you have worked with Docker, chances are you also know about Docker Compose, which is a tool for orchestrating several containers that might be interdependent. To learn more about Docker Compose see its documentation.

What is Podman Compose?


Podman Compose is a project whose goal is to be used as an alternative to Docker Compose without needing any changes to be made in the docker-compose.yaml file. Since Podman Compose works using pods, it’s good to check a refresher definition of a pod.

A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage/network resources, and a specification for how to run the containers.

Pods – Kubernetes Documentation

The basic idea behind Podman Compose is that it picks the services defined inside the docker-compose.yaml file and creates a container for each service. A major difference between Docker Compose and Podman Compose is that Podman Compose adds the containers to a single pod for the whole project, and all the containers share the same network. It even names the containers the same way Docker Compose does, using the ‐‐add-host flag when creating the containers, as you will see in the example.

Installation


Complete install instructions for Podman Compose are found on its project page, and there are several ways to do it. To install the latest development version, use the following command:

pip3 install https://github.com/containers/podman-com...vel.tar.gz

Make sure you also have Podman installed since you’ll need it as well. On Fedora, to install Podman use the following command:

sudo dnf install podman

Example: launching a WordPress site with Podman Compose


Imagine your docker-compose.yaml file is in a folder called wpsite. A typical docker-compose.yaml (or docker-compose.yml) for a WordPress site looks like this:

version: "3.8"
services: web: image: wordpress restart: always volumes: - wordpress:/var/www/html ports: - 8080:80 environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_USER: magazine WORDPRESS_DB_NAME: magazine WORDPRESS_DB_PASSWORD: 1maGazine! WORDPRESS_TABLE_PREFIX: cz WORDPRESS_DEBUG: 0 depends_on: - db networks: - wpnet db: image: mariadb:10.5 restart: always ports: - 6603:3306 volumes: - wpdbvol:/var/lib/mysql environment: MYSQL_DATABASE: magazine MYSQL_USER: magazine MYSQL_PASSWORD: 1maGazine! MYSQL_ROOT_PASSWORD: 1maGazine! networks: - wpnet
volumes: wordpress: {} wpdbvol: {} networks: wpnet: {}

If you come from a Docker background, you know you can launch these services by running docker-compose up. Docker Compose will create two containers named wpsite_web_1 and wpsite_db_1, and attaches them to a network called wpsite_wpnet.

Now, see what happens when you run podman-compose up in the project directory. First, a pod is created named after the directory in which the command was issued. Next, it looks for any named volumes defined in the YAML file and creates the volumes if they do not exist. Then, one container is created per every service listed in the services section of the YAML file and added to the pod.

Naming of the containers is done similar to Docker Compose. For example, for your web service, a container named wpsite_web_1 is created. Podman Compose also adds localhost aliases to each named container. Then, containers can still resolve each other by name, although they are not on a bridge network as in Docker. To do this, use the option –add-host. For example, –add-host web:localhost.

Note that docker-compose.yaml includes a port forwarding from host port 8080 to container port 80 for the web service. You should now be able to access your fresh WordPress instance from the browser using the address http://localhost:8080.

WordPress Dashboard

Controlling the pod and containers


To see your running containers, use podman ps, which shows the web and database containers along with the infra container in your pod.

 
CONTAINER ID  IMAGE                               COMMAND               CREATED      STATUS          PORTS                                         NAMES
a364a8d7cec7  docker.io/library/wordpress:latest  apache2-foregroun...  2 hours ago  Up 2 hours ago  0.0.0.0:8080->80/tcp, 0.0.0.0:6603->3306/tcp  wpsite_web_1
c447024aa104  docker.io/library/mariadb:10.5      mysqld                2 hours ago  Up 2 hours ago  0.0.0.0:8080->80/tcp, 0.0.0.0:6603->3306/tcp  wpsite_db_1
12b1e3418e3e  k8s.gcr.io/pause:3.2

You can also verify that a pod has been created by Podman for this project, named after the folder in which you issued the command.

 
POD ID        NAME             STATUS    CREATED      INFRA ID      # OF CONTAINERS
8a08a3a7773e  wpsite           Degraded  2 hours ago  12b1e3418e3e  3

To stop the containers, enter the following command in another command window:

podman-compose down

You can also do that by stopping and removing the pod. This essentially stops and removes all the containers and then the containing pod. So, the same thing can be achieved with these commands:

podman pod stop podname
podman pod rm podname

Note that this does not remove the volumes you defined in docker-compose.yaml. So, the state of your WordPress site is saved, and you can get it back by running this command:

podman-compose up

In conclusion, if you’re a Podman fan and do your container jobs with Podman, you can use Podman Compose to manage your containers in development and production.



https://www.sickgaming.net/blog/2021/01/...n-compose/
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Fedora - Getting started with COBOL development on Fedora Linux 33 xSicKxBot 0 1 02-28-2021, 01:55 PM
Last Post: xSicKxBot
  Fedora - Contribute at the Fedora Audio, Kernel 5.11 and i18n test days xSicKxBot 0 7 02-26-2021, 01:09 PM
Last Post: xSicKxBot
  Fedora - Installing Nextcloud 20 on Fedora Linux with Podman xSicKxBot 0 29 02-16-2021, 07:51 AM
Last Post: xSicKxBot
  Fedora - Fedora Aarch64 on the SolidRun HoneyComb LX2K xSicKxBot 0 31 02-09-2021, 08:05 AM
Last Post: xSicKxBot
  Fedora - Astrophotography with Fedora Astronomy Lab: setting up xSicKxBot 0 34 02-06-2021, 04:07 AM
Last Post: xSicKxBot
  Fedora - Join Fedora at FOSDEM 2021 xSicKxBot 0 40 02-02-2021, 08:23 AM
Last Post: xSicKxBot
  Fedora - Deploy your own Matrix server on Fedora CoreOS xSicKxBot 0 47 01-21-2021, 05:40 AM
Last Post: xSicKxBot
  Fedora - Discover Fedora Kinoite: a Silverblue variant with the KDE Plasma desktop xSicKxBot 0 40 01-20-2021, 10:59 PM
Last Post: xSicKxBot
  Fedora - Java development on Fedora Linux xSicKxBot 0 39 01-20-2021, 11:29 AM
Last Post: xSicKxBot
  Fedora - A 2020 love letter to the Fedora community xSicKxBot 0 44 01-19-2021, 08:57 PM
Last Post: xSicKxBot

Forum Jump:

[-]
Active Threads
[Tut] How to Compare Rpm Versions in Pyt...
Last Post: xSicKxBot
Yesterday 07:10 PM
» Replies: 0
» Views: 2
(Indie Deal) The Walking Dead, ENCODYA, ...
Last Post: xSicKxBot
Yesterday 07:10 PM
» Replies: 0
» Views: 2
Dem Bones Open Source Animation Skinning...
Last Post: xSicKxBot
Yesterday 02:03 PM
» Replies: 0
» Views: 3
Mobile - Invictus: Lost Soul launches gl...
Last Post: xSicKxBot
Yesterday 02:03 PM
» Replies: 0
» Views: 1
News - Video: Watch Post Malone’s Virtua...
Last Post: xSicKxBot
Yesterday 02:02 PM
» Replies: 0
» Views: 235
News - Memory Pak: When Harvest Moon Tau...
Last Post: xSicKxBot
Yesterday 02:02 PM
» Replies: 0
» Views: 2
News - Pokemon Legends: Arceus' Starter ...
Last Post: xSicKxBot
Yesterday 02:02 PM
» Replies: 0
» Views: 3
Official Sick Gaming Social Links: Twitt...
Last Post: Isaacaleva
Yesterday 11:04 AM
» Replies: 3
» Views: 6053
Sick Gaming Welcomes All Gamers
Last Post: Bryanthusy
Yesterday 07:29 AM
» Replies: 2
» Views: 9968
(Indie Deal) FREE CMC: Ice Crusade, 80% ...
Last Post: xSicKxBot
Yesterday 03:46 AM
» Replies: 0
» Views: 3

[-]
Twitter

[-]
Sponsored
Get the Deal of the Week at RefurBees.com

Copyright © SickGaming.net 2012-2020