Running containers with Podman.
Published: 2023-06-20 17:39:40

---
title: Running containers with Podman.
published: true
date: 2023-02-20 15:06:44 UTC
tags: 
canonical_url: https://carlosmv.hashnode.dev/running-containers-with-podman
---

DISCLAIMER: This is not a comprehensive guide about Podman.

In this article, we are going to create an image container from a Dockerfile. And run a Django application with Podman.

We will not build an application from scratch. We will focus on using Podman to create an image container for our web application and run a container.

Also, you should know what a Dockerfile, images and containers are.

We will create an image for this [Django Application. Y](https://github.com/carlosm27/django_authentication)ou can clone it or create a Django project from scratch. And copy/paste the Dockerfile and `requirements.txt` file.

### Requirements

- WSL2 installed (Windows users).

- Python installed.

- Podman installed.

- Buildah installed.

### What is Podman?

According to its [documentation](https://docs.podman.io/en/latest/):

> Podman is a daemonless, open source, Linux native tool designed to make it easy to find, run, build, share and deploy applications using Open Containers Initiative (OCI) Containers and Container Images. Podman provides a command line interface (CLI) familiar to anyone who has used the Docker Container Engine.

Its [README](https://github.com/containers/podman) file says Podman is a tool for managing containers and images, and volumes mounted into those containers. And pods made from groups of containers.

Podman runs containers on Linux. But it can be used on Mac and Windows systems using a Podman-managed virtual machine.

### Installation

To make this article shorter, I will skip the installation of Podman on Linux, Windows and MacOS. You can refer to the [Podman Installation Instructions](https://podman.io/getting-started/installation). It offers a detailed explanation of how to install Podman on Windows MacOS.

For Ubuntu users and WSL2 users with Ubuntu installed, this is the command to install Podman:

```
sudo apt-get -y update
sudo apt-get -y install podman

```

### Project structure

```
django_authentication/
    django_authentication/
    user_auth/
    Dockerfile
    manage.py
    requirements.txt

```

### Dockerfile

```

RUN mkdir /code
WORKDIR /code
RUN pip install --upgrade pip
COPY requirements.txt /code/

RUN pip install -r requirements.txt
COPY . /code/

EXPOSE 8000

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

```

### Creating an image

Inside our project directory, we run the `build` command to build an image from a Dockerfile.

```
podman build -t django_auth .

```

According to its documentation:

> `podman build` Builds an image using instructions from one or more Containerfiles or Dockerfiles and a specified build context directory. A Containerfile uses the same syntax as a Dockerfile internally. For this document, a file referred to as a Containerfile can be a file named either Containerfile or Dockerfile.
> 
> The build context directory can be specified as the http(s) URL of an archive, git repository or Containerfile.
> 
> If no context directory is specified, then Podman will assume the current working directory as the build context, which should contain the Containerfile.

The `--tag` or `-t` specifies which name Podman will assign to the resulting image if the build process completes. If we don't include a name, the registry will prepend the name _localhost_ to the image name.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1676567749232/ee68364d-1bba-4a87-9814-46764614751f.png)

We can run `podman images` command to display a list of locally stored images, their names and their IDs.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1676568063083/5f049c6c-89be-478b-be5b-13a7e2917233.png)

There are more details in its [documentation](https://docs.podman.io/en/latest/markdown/podman-images.1.html).

### Running a Container

```
podman run --rm -p 8123:8000 django_buildah

```

The documentation says `podman run` runs a process in a new container. With its filesystem, its network and its isolated process tree.

Also, we use `--rm` to automatically remove the container when it exits. And use `-p` or `--port` to map the Django app port 8000 to the host port 8123.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1676581851583/ab7a52c3-ac70-4683-a2fc-ace63c1956fa.png)

For this app, we have to go to `localhost:8123/home` to see a page.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1676581968386/b69d9a0e-5a50-45d4-86a0-f62faf0d8d14.png)

If we go to `localhost:8123`, you will see a _Page Not Found_ page, but still means the container is running.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1676582181762/a5dd3fb1-a945-4eda-a7db-b009383dce4f.png)

If you used a black Django project, you will the Django Welcome Page.

We can open another terminal and run `podman container ls` to see a list of running containers on the system.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1676583021762/6bdc0f57-614b-49b9-ab80-3d4ff138f597.png)

### Deleting an image

We run the `podman --rmi <IMAGE NAME>` to remove an image container. If we pass the name of the image we are using, Podman will remove it. We can run `podman images` again and verify the CLI tool removed the image.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1676583542269/71f5e91e-20ad-4658-bcc7-da62e53d1c33.png)

Podman removed `django_auth`.

### Conclusion

Podman offers many functions that it will need writing another article to explain them. I didn't try using Podman for running more than one container like we usually do with Compose. But it is something a want to try and write about.

I hope you found this article useful and that it encourages you to try Podman.

Thank you for taking the time to read this article.

If you have any recommendations about other packages, architectures, how to improve my code, my English, or anything; please leave a comment or contact me through [**Twitter**](https://twitter.com/Carlos_marcv), or [**LinkedIn**](https://www.linkedin.com/in/carlos-marcano-a2135a134/).

### References

- [Podman's README](https://github.com/containers/podman.io/)

- [Documentation](https://docs.podman.io/en/latest/)

- [Podman's commands](https://docs.podman.io/en/latest/Commands.html)