How to publish a Docker image to Docker Hub using Podman

Podman is a tool for managing containers and pods, and does not require a container daemon as common in the Docker world. All containers and Pods are created as child processes of the Podman tool. Podman’s CLI (podman) is based on the Docker CLI. In this guide, we will show you how to use Podman to create a Docker image and publish / push it to Docker Hub.

Before you start, make sure that podman is installed on your system. You can refer to the following guides:

How to install Podman on Debian

How to install Podman on Arch Linux / Manjaro

How to install Podman on CentOS and Fedora

Install Podman on Ubuntu

How to install and use Podman on CentOS 8 / RHEL 8

Create your Docker image. To do this, I will create a simple Node.js application.

$ mkdir ~/docker-images/demo/
$ cd ~/docker-images/demo/

This 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.end("You've hit " + os.hostname() + "n");

var www = http.createServer(handler);

Create a Dockerfile.

$ vim Dockerfile 
FROM node
ADD app.js /app.js
ENTRYPOINT ["node", "app.js"]

Build images with tags.

$ podman build -t .
STEP 1: FROM node
STEP 2: ADD app.js /app.js
STEP 3: ENTRYPOINT ["node", "app.js"]

Replace with the label of your application.

Login to Docker Hub

$ podman login                           
Username: jmutai
Login Succeeded!

Since I have tagged the image at build time in the format required by Docker Hub, I can push it directly.

$ podman push

Use podman to extract Docker images from Docker Hub

You can then extract the image on other computers by running the following command:

--- Using docker client ---
$ docker pull
$ docker pull jmutai/nodejs-demo:v1

--- Using podman ---
$ podman pull
$ podman pull jmutai/nodejs-demo:v1

Run a test container:

--- With podman ---
$ podman  run --name nodejs-demo -p 8080:8080 -d

--- With Docker ---
$ docker run --name nodejs-demo -p 8080:8080 -d

Try to access your application now http: // localhost: 8080 (If necessary, replace localhost with the hostname or IP of the Docker host):

$ curl localhost:8080
You've hit d1a669579a39

Confirm container ID to verify output

$ podman ps                                                                         
CONTAINER ID  IMAGE                            COMMAND  CREATED             STATUS                 PORTS                   NAMES
d1a669579a39           About a minute ago  Up About a minute ago>8080/tcp  nodejs-demo

Clean environment:

$ podman rm -f d1a669579a39
$ docker rm -f d1a669579a39

Like using Podman to run container images. For more information on Podman, please check:

How to run Docker containers with Podman and Libpod