How to Deploy Containers on Linux?

Deploying Containers on Linux

Containers have revolutionized the way we deploy applications, offering portability and efficiency. In this guide, we'll walk you through the process of deploying containers on a Linux system using Podman, a popular container management tool that offers a daemonless and rootless approach.

Prerequisites

Before we start, ensure you have Podman installed on your Linux system. If it's not installed yet, you can install it using your package manager.

Step 1: Verify Podman Installation

First, let's verify if Podman is installed on your system. Open your terminal and run:

dnf list podman

This command will list the Podman package details if it's installed. If not, you can install it using:

Step 2: Check Existing Images

To see what container images you have already downloaded, use the following command:

podman images

This will list all the container images available on your system.

Step 3: Run a Container

Now, let's run a container. For this example, we'll use a hypothetical image called mysite. We'll allocate 0.256 CPUs and 128MB of memory to this container, map port 80 of the container to port 80 of the host, and name the container c1.

podman run -dit --cpus 0.256 --memory 128M -p 80:80 --name c1 mysite
  • -dit: Run the container in detached mode with an interactive terminal.
  • --cpus 0.256: Limit the container to 0.256 CPUs.
  • --memory 128M: Limit the container to 128MB of memory.
  • -p 80:80: Map port 80 of the host to port 80 of the container.
  • --name c1: Name the container c1.
  • mysite: The name of the container image.

Step 4: Verify the Container is Running

To verify that your container is running, use:

podman ps -a

This will list all containers, including those that are running, stopped, or in other states.

Step 5: Inspect the Container

To get detailed information about the container, including its IP address, run:

podman inspect c1

Look for the IP address in the output. You'll use this IP address to access your containerized application.

Step 6: Access Your Application

Open your web browser and go to:

http://<IP>

Replace with the actual IP address obtained from the inspect command. You should see your application running.

Step 7: Stop the Container

When you're done, you can stop the container with:

podman stop c1

Step 8: Remove the Container

To remove the container completely, use:

podman rm c1

Conclusion

Congratulations! You've successfully deployed a container on your Linux system using Podman. This guide covered the basics, from verifying installation to running, accessing, stopping, and removing a container. Podman offers a robust and flexible way to manage containers, making it a great choice for Linux users. Happy containerizing!