In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to manage containers with Podman Compose". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn "how to manage containers with Podman Compose".
The container is great, allowing you to package your application with its dependencies and run anywhere. Since Docker in 2013, containers have made life easier for software developers.
One disadvantage of Docker is that it has a central daemon that runs as the root user, which has an impact on security. But this is Podman's opportunity to use his talents. Podman is a daemon-free container engine for developing, managing, and running OCI containers in root or root-free mode on your Linux system.
The following articles can be used to learn more about Podman:
Use Podman to run the Linux container as a non-root user
Using Podman's Pod on Fedora
Combine the right to use Podman in Fedora
If you have used Docker, you probably know Docker Compose, which is a tool for orchestrating multiple containers that may be interdependent. To learn more about Docker Compose, see its documentation.
What is Podman Compose?
The goal of the Podman Compose project is to act as a substitute for Docker Compose without requiring any changes to the docker-compose.yaml file. Since Podman Compose works with the pod pod, it is best to take a look at the latest definition of "pod".
A "pod pod" (such as a herd of whales or pea pods) is a group of one or more containers with shared storage / network resources and specifications for how to run the container.
Pods-Kubernetes document
(LCTT translation note: nautical metaphors are widely used in the field of container technology. The word pod means "pod". In the nautical field, it refers to "pods"-all refers to containers containing multiple items. Often do not translate, consider the text before and after, can be translated as "pod". )
The basic idea of Podman Compose is that it selects the services defined in the docker-compose.yaml file and creates a container for each service. One of the main differences between Docker Compose and Podman Compose is that Podman Compose adds containers for the entire project to a single pod, and all containers share the same network. As you can see in the example, use the-add-host flag when creating the container, which even names the container in the same way as Docker Compose.
Installation
Complete installation instructions for Podman Compose can be found on the 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-compose/archive/devel.tar.gz
Make sure you also have Podman installed, because you need it, too. On Fedora, install Podman using the following command:
Sudo dnf install podman example: launch a WordPress website with Podman Compose
Imagine that your docker-compose.yaml file is in a folder called wpsite. The docker-compose.yaml (or docker-compose.yml) file of a typical WordPress website looks like this:
Version: "3.8" services: web: image: wordpress restart: always volumes:-wordpress:/var/www/html ports:-8080 db WORDPRESS_DB_USER 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 MYSQL_DATABASE 3306 volumes:-wpdbvol:/var/lib/mysql environment: magazine MYSQL_USER: magazine MYSQL_PASSWORD: 1maGazine! MYSQL_ROOT_PASSWORD: 1maGazine! Networks:-wpnetvolumes: wordpress: {} wpdbvol: {} networks: wpnet: {}
If you have used Docker, you will know that you can run docker-compose up to start these services. Docker Compose creates two containers named wpsite_web_1 and wpsite_db_1 and connects them to a network called wpsite_wpnet.
Now, see what happens when you run podman-compose up in the project directory. First, a pod named after the directory where the command was executed is created. Next, it looks for volumes of any name defined in the YAML file, and if they don't exist, it creates the volume. Each service listed in the services section of the YAML file then creates a container and adds it to the pod.
The naming of the container is similar to Docker Compose. For example, create a container called wpsite_web_1 for your web service. Podman Compose also adds a localhost alias for each named container. After that, containers can still resolve each other by name, although they are not on a bridged network like Docker. To do this, use the option-add-host. For example,-add-host web:localhost.
Note that docker-compose.yaml contains a port forwarding of the Web service from host port 8080 to container port 80. You should now be able to access the new WordPress instance through your browser at http://localhost:8080.
WordPress Dashboard
Control pod and containers
To see which containers are running, use podman ps, which displays web and database containers as well as infrastructure containers in the pods.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESa364a8d7cec7 docker.io/library/wordpress:latest apache2-foregroun... 2 hours ago Up 2 hours ago 0.0.0.0 hours ago Up 8080-> 80/tcp, 0.0.0.0 80/tcp 6603-> 3306/tcp wpsite_web_1c447024aa104 docker.io/library/mariadb:10.5 mysqld 2 hours ago Up 2 80/tcp 0.0.0.0 80/tcp 8080-> 80/tcp, 0.0.0.0 80/tcp 6603-> 3306/tcp wpsite_db_112b1e3418e3e k8s.gcr.io/pause:3.2
You can also verify that Podman has created a pod for this project, named after the folder where you executed the command.
POD ID NAME STATUS CREATED INFRA ID # OF CONTAINERS8a08a3a7773e wpsite Degraded 2 hours ago 12b1e3418e3e 3
To stop the container, enter the following command in another command window:
Podman-compose down
You can also do this by stopping and deleting the pods. This essentially stops and removes all containers and then deletes the included pods. So, the same thing can be done through these commands:
Podman pod stop podnamepodman pod rm podname
Please note that this will not delete the volume you defined in docker-compose.yaml. So, the state of your WordPress site has been saved, and you can restore it by running this command.
Podman-compose up
In short, if you are a Podman fan and use Podman for container work, you can use Podman Compose to manage containers in your development and production.
Thank you for your reading, the above is the content of "how to manage containers with Podman Compose". After the study of this article, I believe you have a deeper understanding of how to manage containers with Podman Compose, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.