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

var www = http.createServer(handler);
www.listen(8080);

Create a Dockerfile.

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

Build images with tags.

$ 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 label of your application.

Login to Docker Hub

$ podman login docker.io                           
Username: jmutai
Password: 
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 docker.io/jmutai/nodejs-demo:v1

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.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

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  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 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

Sidebar