Posted on • Originally published atcarlosmv.hashnode.dev on
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 thisDjango Application. You can clone it or create a Django project from scratch. And copy/paste the Dockerfile andrequirements.txt
file.
Requirements
WSL2 installed (Windows users).
Python installed.
Podman installed.
Buildah installed.
What is Podman?
According to itsdocumentation:
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.
ItsREADME 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 thePodman Installation Instructions. 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 updatesudo apt-get -y install podman
Project structure
django_authentication/ django_authentication/ user_auth/ Dockerfile manage.py requirements.txt
Dockerfile
RUN mkdir /codeWORKDIR /codeRUN pip install --upgrade pipCOPY requirements.txt /code/RUN pip install -r requirements.txtCOPY . /code/EXPOSE 8000CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
Creating an image
Inside our project directory, we run thebuild
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 namelocalhost to the image name.
We can runpodman images
command to display a list of locally stored images, their names and their IDs.
There are more details in itsdocumentation.
Running a Container
podman run --rm -p 8123:8000 django_buildah
The documentation sayspodman 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.
For this app, we have to go tolocalhost:8123/home
to see a page.
If we go tolocalhost:8123
, you will see aPage Not Found page, but still means the container is running.
If you used a black Django project, you will the Django Welcome Page.
We can open another terminal and runpodman container ls
to see a list of running containers on the system.
Deleting an image
We run thepodman --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 runpodman images
again and verify the CLI tool removed the image.
Podman removeddjango_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 throughTwitter, orLinkedIn.
References
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse