Podman is a tool designed for managing containers and pods without requiring a container daemon as common in Docker world. All the containers and Pods are created as child processes of the Podman tool. The Podman’s CLI (podman) is based on the Docker CLI. In this guide we’ll show you how to create and publish/push Docker images to Docker Hub using Podman.
If you want to build a private container registry with podman, check our guide below:
Before you begin, ensure you have podman installed in your system. Here are the guides you can refer to:
- How To Install Podman on Debian
- How To Install Podman on Arch Linux / Manjaro
- How To Install Podman on CentOS & Fedora
- Install Podman on Ubuntu
- How To Install and Use Podman on CentOS 8 / RHEL 8
Create your Docker image. For this I’ll create a simple Node.js Application.
mkdir ~/docker-images/demo/
cd ~/docker-images/demo/
Here is my app.js file.
$ vim app.js
const http = require('http');
const os = require('os');
console.log("Node server starting...");
var handler = function(request, response)
console.log("Received request from " + request.connection.remoteAddress);
response.writeHead(200);
response.end("You've hit " + os.hostname() + "\n");
;
var www = http.createServer(handler);
www.listen(8080);
Create Dockerfile.
$ vim Dockerfile
FROM node
ADD app.js /app.js
ENTRYPOINT ["node", "app.js"]
Build image with a tag.
$ podman build -t docker.io/jmutai/nodejs-demo:v1 .
STEP 1: FROM node
STEP 2: ADD app.js /app.js
afbd0b73b68748a693427c1ed7bf4a40d293632691b385a565a40d0d1092b4de
STEP 3: ENTRYPOINT ["node", "app.js"]
STEP 4: COMMIT docker.io/jmutai/nodejs-demo:v1
ffe0449e93f36fddecc71e701a6011dbbfa0cfcdf6565209c84b845bfca60bae
Replace docker.io/jmutai/nodejs-demo:v1 with the tag for your application.
Login to Docker hub
$ podman login docker.io
Username: jmutai
Password:
Login Succeeded!
Since I had tagged the image at build in format required by Docker Hub, I can just push it.
$ podman push docker.io/jmutai/nodejs-demo:v1
Pulling Docker image from Docker Hub with podman
You can then pull image on other machines by running:
### Using docker client ###
docker pull docker.io/jmutai/nodejs-demo:v1
docker pull jmutai/nodejs-demo:v1
### Using podman ###
podman pull docker.io/jmutai/nodejs-demo:v1
podman pull jmutai/nodejs-demo:v1
Run a test container:
### With podman ###
$ podman run --name nodejs-demo -p 8080:8080 -d docker.io/jmutai/nodejs-demo:v1
d1a669579a39580fd1dfa19aaeed2c7a29aa28a1324d87c301d20f41e30e014f
### With Docker ###
$ docker run --name nodejs-demo -p 8080:8080 -d docker.io/jmutai/nodejs-demo:v1
Now try to access your application at http://localhost:8080 (Replace localhost with the hostname or IP of the Docker host if necessary):
$ curl localhost:8080
You've hit d1a669579a39
Confirm container ID to validate the output
$ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d1a669579a39 docker.io/jmutai/nodejs-demo:v1 About a minute ago Up About a minute ago 0.0.0.0:8080->8080/tcp nodejs-demo
Clean your environment:
$ podman rm -f d1a669579a39
$ docker rm -f d1a669579a39
Enjoy using Podman to run container images. For more on Podman check: