Podman for Docker Users

Podman is the command-line interface tool that lets you interact with Libpod, a library for running and managing OCI-based containers. It is important to note that Podman doesn't depend on a daemon, and it doesn't require root privileges.

The first part of this tutorial focuses on similarities between Podman and Docker, and we'll show how you can do the following:

In the second part of this tutorial, we'll walk you through two of the most important features that differentiate Podman from Docker. In this section, you will do the following:

Prerequisites

  1. This tutorial is intended for readers who have prior exposure to Docker. In the next sections, you will use commands such as run, build, push, commit, and tag. It is beyond the scope of this tutorial to explain how these commands work.
  2. A running Linux system with Podman and Docker installed.

You can enter the following command to check that Podman is installed on your system:

Shell
 




x


1
podman version


Plain Text
 




xxxxxxxxxx
1


 
1
Version:            1.6.4 
2
RemoteAPI Version:  1 
3
Go Version:         go1.12.12 
4
OS/Arch:            linux/amd64


Refer Podman Installation Instructions for details on how to install Podman.

Use the following command to verify if Docker is installed:

Shell
 




xxxxxxxxxx
1


 
1
docker --version


Plain Text
 




xxxxxxxxxx
1


 
1
Docker version 18.06.3-ce, build d7080c1


See the Get Docker page for details on how to install Docker.

  1. Git. To check if Git is installed on your system enter, type the following command:
Shell
 




xxxxxxxxxx
1


1
git version


Plain Text
 




xxxxxxxxxx
1


 
1
git version 2.18.2
2
 
          


You can refer Getting Started - Installing Git on details of installing Git.

  1. Node.js 10 or higher. To check if Node.js is installed on your computer, type the following command:
node --version
v10.16.3

If Node.js is not installed, you can download the installer from the Downloads page.

Moving Images from Docker to Podman

If you've just installed Podman on a system on which you've already used Docker to pull one or more images, you'll notice that running the podman images command doesn't show your Docker images:

Shell
 




xxxxxxxxxx
1


 
1
docker images


REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE 
cassandra           latest              b571e0906e1b        10 days ago         324MB
Shell
 




xxxxxxxxxx
1


 
1
podman images
2
 
          


REPOSITORY   TAG   IMAGE ID   CREATED   SIZE

The reason why you don't see your Docker images is that Podman runs without root privileges. Thus, its repository is located in the user's home directory - ~/.local/share/containers. However, Podman can import an image directly from the Docker daemon running on your machine, through the docker-daemon  transport.

In this section, you'll use Docker to pull the hello-world image. Then, you'll import it into Podman. Lastly, you'll run the hello-world image with Podman.

  1. Download and run the hello-world image by executing the following command:
Shell
 




x


 
1
sudo docker run hello-world


Unable to find image 'hello-world:latest' locally 
latest: Pulling from library/hello-world 
1b930d010525: Pull complete 
Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f 
Status: Downloaded newer image for hello-world:latest 

Hello from Docker! 
This message shows that your installation appears to be working correctly. 

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal. 

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash 

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/ 

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
  1. The following docker images command lists the Docker images on your system and pretty-prints the output:
Shell
 




xxxxxxxxxx
1


 
1
sudo docker images --format '{{.Repository}}:{{.Tag}}'


hello-world:latest
  1. Enter the podman pull command specifying the transport (docker-daemon) and the name of the image, separated by ::
Shell
 




xxxxxxxxxx
1


1
podman pull docker-daemon:hello-world:latest


Getting image source signatures 
Copying blob af0b15c8625b done 
Copying config fce289e99e done 
Writing manifest to image destination 
Storing signatures 
fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e


  1. Once you've imported the image, running the podman images command will display the hello-world image:
Shell
 




xxxxxxxxxx
1


1
podman images


REPOSITORY                      TAG      IMAGE ID       CREATED         SIZE 
docker.io/library/hello-world   latest   fce289e99eb9   13 months ago   5.94 kB
  1. To run the image, enter the following podman run command:
Shell
 




xxxxxxxxxx
1


1
podman run hello-world


podman run hello-world
Shell
 




x
20


1
Hello from Docker!
2
This message shows that your installation appears to be working correctly.
3
 
          
4
To generate this message, Docker took the following steps:
5
 1. The Docker client contacted the Docker daemon.
6
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
7
    (amd64)
8
 3. The Docker daemon created a new container from that image which runs the
9
    executable that produces the output you are currently reading.
10
 4. The Docker daemon streamed that output to the Docker client, which sent it
11
    to your terminal.
12
 
          
13
To try something more ambitious, you can run an Ubuntu container with:
14
 $ docker run -it ubuntu bash
15
 
          
16
Share images, automate workflows, and more with a free Docker ID:
17
 https://hub.docker.com/
18
 
          
19
For more examples and ideas, visit:
20
 https://docs.docker.com/get-started/



Creating a Basic Nuxt.js Project

For the scope of this tutorial, we’ll create a simple web-application using Nuxt.JS, a progressive Vue-based framework that aims to provide a great experience for developers. Then, in the next sections, you'll use Podman to create a container image for your project and push it Quay.io. Lastly, you'll use Docker to run the container image.

  1. Nuxt.JS is distributed as an NPM package. To install it, fire up a terminal window, and execute the following command:
Shell
 




xxxxxxxxxx
1


 
1
npm install nuxt
2



+ nuxt@2.11.0 
added 1067 packages from 490 contributors and audited 9750 packages in 75.666s 
found 0 vulnerabilities

Note that the above output was truncated for brevity.

  1. With Nuxt.JS installed on your computer, you can create a new bare-bones project:
npx create-nuxt-app podman-nuxtjs-demo

You will be prompted to answer a few questions:

Shell
 




xxxxxxxxxx
1
14


1
create-nuxt-app v2.14.0
2
  Generating Nuxt.js project in podman-nuxtjs-demo
3
? Project name podman-nuxtjs-demo
4
? Project description Podman Nuxt.JS demo
5
? Author name Appfleet
6
? Choose the package manager Npm
7
? Choose UI framework Bootstrap Vue
8
? Choose custom server framework None (Recommended)
9
? Choose Nuxt.js modules (Press <space> to select, <a> to toggle all, <i> to invert selectio
10
n)
11
? Choose linting tools ESLint
12
? Choose test framework None
13
? Choose rendering mode Universal (SSR)
14
? Choose development tools jsconfig.json (Recommended for VS Code)



Once you answer these questions, npm will install the required dependencies: 

Shell
 




xxxxxxxxxx
1
12


 
1
��  Successfully created project podman-nuxtjs-demo
2
 
          
3
  To get started:
4
 
          
5
 cd podman-nuxtjs-demo
6
 npm run dev
7
 
          
8
  To build & start for production:
9
 
          
10
 cd podman-nuxtjs-demo
11
 npm run build
12
 npm run start



Note that the above output was truncated for brevity.

  1. Enter the following commands to start your new application:
cd podman-nuxtjs-demo/ && npm run dev


Shell
 




xxxxxxxxxx
1
26


 
1
> podman-nuxtjs-demo@1.0.0 dev /home/vagrant/podman-nuxtjs-demo
2
> nuxt
3
 
          
4
 
          
5
   ╭─────────────────────────────────────────────╮
6
   │                                             │
7
   │   Nuxt.js v2.11.0                           │
8
   │   Running in development mode (universal)   │
9
   │                                             │
10
   │   Listening on: http://localhost:3000/      │
11
   │                                             │
12
   ╰─────────────────────────────────────────────╯
13
 
          
14
ℹ Preparing project for development                                               14:39:30
15
ℹ Initial build may take a while                                                  14:39:30
16
 Builder initialized                                                             14:39:30
17
 Nuxt files generated                                                            14:39:30
18
 
          
19
 Client
20
  Compiled successfully in 23.53s
21
 
          
22
 Server
23
  Compiled successfully in 17.82s
24
 
          
25
ℹ Waiting for file changes                                                        14:39:56
26
ℹ Memory usage: 209 MB (RSS: 346 MB)                                              14:39:56



  1. Point your browser to http://localhost:3000, and you should see something similar to the screenshot below:

Building a Container Image for Your Nuxt.JS Project

In this section, we'll look at how you can use Podman to build a container image for thepodman-nextjs-demo project.

  1. Create a file called Dockerfile and place the following content into it:
FROM node:10 
WORKDIR /usr/src/app 
COPY package*.json ./ 
RUN npm install 
COPY . . 
EXPOSE 3000 
CMD [ "npm", "run", "dev" ]

For a quick refresher on the above Dockerfile commands, refer the Create a Docker Image section from the Debug a Node.js Application Running in a Docker Container tutorial.

  1. To avoid sending large files to the build context and speed up the process, create a file called .dockerignore with the following content:
node_modules 
npm-debug.log 
.nuxt

As you can see, this is just a plain-text file containing names of the files and directories that Podman should exclude from the build.

  1. Build the image. Execute the following podman build command, specifying the -t flag with the tagged name Podman will apply to the build image:
podman build -t podman-nuxtjs-demo:podman .
Shell
 




xxxxxxxxxx
1
64


 
1
STEP 1: FROM node:10
2
STEP 2: RUN mkdir -p /usr/src/nuxt-app
3
--> Using cache c7198c4f08b90ecb5575bbce23fc095e5c65fe5dc4b4f77b23192e2eae094d6f
4
STEP 3: WORKDIR /usr/src/nuxt-app
5
--> Using cache f1cc5aba3f36e122513c5ff0410f862d6099bcee886453f7fb30859f66e0ac78
6
STEP 4: COPY . /usr/src/nuxt-app/
7
--> Using cache fb4c322c98b41d446f5cceb88b3f9c451751d0cfe8ed9d0e6eb153919b498da3
8
STEP 5: RUN npm install
9
--> Using cache bb5324e79782b4522048dcc5f0f02c41b56e12198438aa59a7588a6824a435e1
10
STEP 6: RUN npm run build
11
 
          
12
> podman-nuxtjs-demo@1.0.0 build /usr/src/nuxt-app
13
> nuxt build
14
 
          
15
ℹ Production build
16
 Builder initialized
17
 Nuxt files generated
18
 
          
19
 Client
20
  Compiled successfully in 2.95m
21
 
          
22
 Server
23
  Compiled successfully in 10.91s
24
 
          
25
 
          
26
Hash: 7c4493c4d1c7b235dd8e
27
Version: webpack 4.41.6
28
Time: 177257ms
29
Built at: 02/11/2020 4:48:17 PM
30
                         Asset      Size  Chunks                                Chunk Names
31
../server/client.manifest.json  16.1 KiB          [emitted]
32
       7d497fe85470995d6e29.js  2.99 KiB       2  [emitted] [immutable]         pages/index
33
       848739217655a36af267.js   671 KiB       4  [emitted] [immutable]  [big]  vendors.app
34
       90036491716edfc3e86d.js   159 KiB       1  [emitted] [immutable]         commons.app
35
                      LICENSES  1.95 KiB          [emitted]
36
       b625f5fc00e8ff962762.js  2.31 KiB       3  [emitted] [immutable]         runtime
37
       eac7116f7d28455b0958.js    36 KiB       0  [emitted] [immutable]         app
38
 + 2 hidden assets
39
Entrypoint app = b625f5fc00e8ff962762.js 90036491716edfc3e86d.js 848739217655a36af267.js eac7116f7d28455b0958.js
40
 
          
41
WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
42
This can impact web performance.
43
Assets:
44
  848739217655a36af267.js (671 KiB)
45
 
          
46
Hash: e3d9cfd644a086dc9c5b
47
Version: webpack 4.41.6
48
Time: 10916ms
49
Built at: 02/11/2020 4:48:29 PM
50
                  Asset       Size  Chunks                         Chunk Names
51
d1d703b09adf296a453d.js   3.07 KiB       1  [emitted] [immutable]  pages/index
52
              server.js    222 KiB       0  [emitted]              app
53
   server.manifest.json  145 bytes          [emitted]
54
Entrypoint app = server.js
55
0d239b0083a60482b4b5fa60a99b96dd22045822e50fbd83b8a369d8179bf307
56
STEP 7: EXPOSE 3000
57
1d037e041dd4a8d6c94a9f6fb8fe6578f5e00d27aab9168bad83e7ab260bbeae
58
STEP 8: ENV NUXT_HOST=0.0.0.0
59
40d684a5441a8da38ed5198be722719f393be13a855a9e85cbc49e5c7155f7cc
60
STEP 9: ENV NUXT_PORT=3000
61
7d07961e058d66e172f4b9e01d50fb355c16060a990252c5bc7cd35d960f5f72
62
STEP 10: CMD ["npm", "run", "dev"]
63
STEP 11: COMMIT podman-nuxtjs-demo:podman
64
54c55a8a44f30105371652bc2c25e0fbba200ad6c945654077151194aa0a66fe



  1. At this point, you can check that everything went well with:
podman images
REPOSITORY                     TAG      IMAGE ID       CREATED              SIZE 
localhost/podman-nuxtjs-demo   podman   54c55a8a44f3   About a minute ago   1.09 GB 
docker.io/library/node         10       bb78c02ca3bf   4 days ago           937 MB
  1. To run the podman-nuxtjs-demo:podman container, enter the podman run command and pass it the following arguments:
podman run -dt -p 3000:3000/tcp podman-nuxtjs-demo:podman

This will print out to the console the container ID:

4de08084dd1d33fcdae96cd493b3eb20406ea89ce2a3e8dbc833b38c2243ce43
  1. You can list your running containers with:
podman ps
CONTAINER ID  IMAGE                                COMMAND      CREATED        STATUS            PORTS                   NAMES 
4de08084dd1d  localhost/podman-nuxtjs-demo:podman  npm run dev  4 seconds ago  Up 4 seconds ago  0.0.0.0:3000->3000/tcp  objective_neumann
  1. To retrieve detailed information about your running container, enter the podman inspect command specifying the container ID:
podman inspect 4de08084dd1d33fcdae96cd493b3eb20406ea89ce2a3e8dbc833b38c2243ce43
Shell
 




xxxxxxxxxx
1
35


1
podman inspect 4de08084dd1d33fcdae96cd493b3eb20406ea89ce2a3e8dbc833b38c2243ce43
2
[
3
    {
4
        "Id": "4de08084dd1d33fcdae96cd493b3eb20406ea89ce2a3e8dbc833b38c2243ce43",
5
        "Created": "2020-02-11T17:00:06.819669549Z",
6
        "Path": "docker-entrypoint.sh",
7
        "Args": [
8
            "npm",
9
            "run",
10
            "dev"
11
        ],
12
        "State": {
13
            "OciVersion": "1.0.1-dev",
14
            "Status": "running",
15
            "Running": true,
16
            "Paused": false,
17
            "Restarting": false,
18
            "OOMKilled": false,
19
            "Dead": false,
20
            "Pid": 10637,
21
            "ConmonPid": 10628,
22
            "ExitCode": 0,
23
            "Error": "",
24
            "StartedAt": "2020-02-11T17:00:07.317812139Z",
25
            "FinishedAt": "0001-01-01T00:00:00Z",
26
            "Healthcheck": {
27
                "Status": "",
28
                "FailingStreak": 0,
29
                "Log": null
30
            }
31
        },
32
        "Image": "54c55a8a44f30105371652bc2c25e0fbba200ad6c945654077151194aa0a66fe",
33
        "ImageName": "localhost/podman-nuxtjs-demo:podman",
34
        "Rootfs": "",
35
        "Pod": "",



Note that the above output was truncated for brevity.

  1. To retrieve the logs from your container, run the podman logs command specifying the container ID or the --latest flag:
podman logs --latest
Shell
 




xxxxxxxxxx
1
26


 
1
> podman-nuxtjs-demo@1.0.0 dev /usr/src/nuxt-app
2
> nuxt
3
 
          
4
 
          
5
   ╭─────────────────────────────────────────────╮
6
   │                                             │
7
   │   Nuxt.js v2.11.0                           │
8
   │   Running in development mode (universal)   │
9
   │                                             │
10
   │   Listening on: http://10.0.2.100:3000/     │
11
   │                                             │
12
   ╰─────────────────────────────────────────────╯
13
 
          
14
ℹ Preparing project for development
15
ℹ Initial build may take a while
16
 Builder initialized
17
 Nuxt files generated
18
 
          
19
 Client
20
  Compiled successfully in 25.36s
21
 
          
22
 Server
23
  Compiled successfully in 19.21s
24
 
          
25
ℹ Waiting for file changes
26
ℹ Memory usage: 254 MB (RSS: 342 MB)



  1. Display the list of running processes inside your container:
podman top 4de08084dd1d
USER   PID   PPID   %CPU     ELAPSED           TTY     TIME   COMMAND 
root   1     0      0.000    3m52.098907307s   pts/0   0s     npm 
root   17    1      0.000    3m51.099829437s   pts/0   0s     sh -c nuxt 
root   18    17     11.683   3m51.099997015s   pts/0   27s    node /usr/src/nuxt-app/node_modules/.bin/nuxt

Push Your Podman Image to Quay.io

  1. First, you must generate an encrypted password. Point your browser to http://quay.io, and then navigate to the Account Settings page:

  1. On the Account Settings page, select Generate Encrypted Password:

  1. When prompted, enter your Quay.io password:

  1. From the sidebar on the left, select Docker Login. Then, copy your encrypted password:

  1. You can now log in to Quay.io. Enter the podman login command specifying:
podman login quay.io -u <YOUR_USER_NAME> -p="<YOUR_ENCRYPTED_PASSWORD>"
Login Succeeded!
  1. To push the podman-nuxtjs-demo image to Quay.io, enter the following podman push command:
podman push podman-nuxtjs-demo:podman quay.io/andreipope/podman-nuxtjs-demo:podman
Getting image source signatures 
Copying blob 69dfa7bd7a92 done 
Copying blob 4d1ab3827f6b done 
Copying blob 7948c3e5790c done 
Copying blob 01727b1a72df done 
Copying blob 03dc1830d2d5 done 
Copying blob 1d7382716a27 done 
Copying blob 062fc3317d1a done 
Copying blob 3d36b8a4efb1 done 
Copying blob 1708ebc408a9 done 
Copying blob 0aacf878561f done 
Copying blob c49b91e9cfd0 done 
Copying blob 4294ef3571b7 done 
Copying blob 1da55789948c done 
Copying config 54c55a8a44 done 
Writing manifest to image destination 
Copying config 54c55a8a44 done 
Writing manifest to image destination 
Storing signatures

In the above command, do not forget to replace our username (andreipope) with yours.

  1. Point your browser to https://quay.io/, navigate to the podman-nuxtjs-demo repository, and make sure the repository is public:

Run Your Podman Image with Docker

Container images are compatible between Podman and Docker. In this section, you'll use Docker to pull the podman-nuxtjs-demo image from Quay.io and run it. Ideally, you would want to run this on a different machine.

  1. You can log in to Quay.io by entering the docker login command and passing it the following parameters:
docker login -u="<YOUR_USER_NAME>" -p="YOUR_ENCRYPTED_PASSWORD" quay.io
WARNING! Using --password via the CLI is insecure. Use --password-stdin. 
Login Succeeded
  1. To run the podman-nuxtjs-demo image, you can use the following command:
docker run -dt -p 3000:3000/tcp  quay.io/andreipope/podman-nuxtjs-demo:podman
Unable to find image 'quay.io/andreipope/podman-nuxtjs-demo:podman' locally 
podman: Pulling from andreipope/podman-nuxtjs-demo 
03644a8453bd: Pull complete 
e2c9fbbb35b2: Pull complete 
0c33fe27c91c: Pull complete 
957ac2567af6: Pull complete 
934d2e09d84d: Pull complete 
50c60e376f59: Pull complete 
3c43a52a3ecc: Pull complete 
e74942a3267a: Pull complete 
af1466e8bc5b: Pull complete 
3f24948a552e: Pull complete 
df2fea35a007: Pull complete 
7045f2526057: Pull complete 
5090c2f6d806: Pull complete 
Digest: sha256:fcf90cfc3fe1d0f7e975db8a271003cdd51d6f177e490eb39ec1e44d3659b815 
Status: Downloaded newer image for quay.io/andreipope/podman-nuxtjs-demo:podman 
1c0981690d66f2cd8cb77e9573f1dd4e9d7700869e08797b42fc33590d8baabf
  1. Wait a bit until Docker pulls the image and creates the container. Then, issue the the docker ps command to display the list of running containers:
docker ps
CONTAINER ID        IMAGE                                          COMMAND                  CREATED             STATUS              PORTS                    NAMES 
1c0981690d66        quay.io/andreipope/podman-nuxtjs-demo:podman   "docker-entrypoint.s…"   25 seconds ago      Up 20 seconds       0.0.0.0:3000->3000/tcp   practical_bose
  1. To make sure everything works as expected, point your browser to http://localhost:3000. You should see something similar to the screenshot below:

Creating Pods

Until now, you've used Podman similarly to how Docker is used. However, Podman brings a couple of new features such as the ability to create pods. A Pod is a group of tightly-coupled containers that share their storage and network resources. In a nutshell, you can use a Pod to model a logical host. In this section, we'll walk you through the process of creating a Pod comprised of the podman-nuxtjs-demo container and a PostgreSQL database. Note that it is beyond the scope of this tutorial to show how you can configure the storage and network for your Pod.

  1. Create a pod with the podman-nuxtjs-demo container. Enter the podman run with the following arguments:
podman run -dt --pod new:podman_demo -p 3000:3000/tcp quay.io/andreipope/podman-nuxtjs-demo:podman

This will print the identifier of your new Pod:

972c7c1db0c31a42ba4b41025078dfc6abb046f503aa413d6cca313068042041
  1. You can display the list of running Pods with the podman pod list command:
podman pod list
POD ID         NAME             STATUS    CREATED          # OF CONTAINERS   INFRA ID 
d15a2abd9d5b   podman_demo      Running   32 seconds ago   2                 6a5bc0360ae2

In the output above, the number of containers is 2. This is because all Podman Pods include something called an Infra container, which does nothing except that it goes to sleep. This way, it holds the namespace associated with the Pod so that Podman can attach other containers to the Pod.

  1. Print the list of running containers by entering the podman ps command followed by the -a and -p flags. This lists all containers and prints the identifiers and the names of the Pods your containers are associated with:
podman ps -ap
CONTAINER ID  IMAGE                                         COMMAND      CREATED            STATUS                         PORTS                   NAMES                POD 

972c7c1db0c3  quay.io/andreipope/podman-nuxtjs-demo:podman  npm run dev  56 seconds ago     Up 55 seconds ago              0.0.0.0:3000->3000/tcp  festive_yonath       d15a2abd9d5b 

6a5bc0360ae2  k8s.gcr.io/pause:3.1                                       56 seconds ago     Up 55 seconds ago              0.0.0.0:3000->3000/tcp  d15a2abd9d5b-infra   d15a2abd9d5b

As you can see, the Infra container uses the k8s.gcr.io/pause image.

  1. Run the postgres:11-alpine image and associate it with the podman_demo Pod:
podman run -dt --pod podman_demo postgres:11-alpine 
d395bed40988a953257b9501497c66b886b2fb6e81f48aa0ac89d7cfe2639b75
  1. This takes a bit of time to complete. Once everything is ready, you should see that the number of containers has been increased to 3:
 podman pod list
POD ID         NAME             STATUS    CREATED          # OF CONTAINERS   INFRA ID 
d15a2abd9d5b   podman_demo      Running   8 minutes ago    3                 6a5bc0360ae2
  1. You can display the list of your running containers with the following podman ps command:
podman ps -ap
CONTAINER ID  IMAGE                                         COMMAND      CREATED            STATUS                        PORTS                   NAMES                POD 

ab5bd4810494  docker.io/library/postgres:11-alpine          postgres     5 minutes ago      Up 3 minutes ago              0.0.0.0:3000->3000/tcp  dreamy_jackson       d15a2abd9d5b 

972c7c1db0c3  quay.io/andreipope/podman-nuxtjs-demo:podman  npm run dev  9 minutes ago      Up 9 minutes ago              0.0.0.0:3000->3000/tcp  festive_yonath       d15a2abd9d5b 

6a5bc0360ae2  k8s.gcr.io/pause:3.1                                       9 minutes ago      Up 9 minutes ago
  1. As an example, you can stop the podman-nuxtjs-demo container. The other containers in the Pod won't be affected, and the status of the Pod will show as Running:
podman stop 972c7c1db0c3
972c7c1db0c31a42ba4b41025078dfc6abb046f503aa413d6cca313068042041
podman pod ps
POD ID         NAME             STATUS    CREATED          # OF CONTAINERS   INFRA ID 
d15a2abd9d5b   podman_demo      Running   12 minutes ago   3                 6a5bc0360ae2
  1. To start again the container, enter the podman start command followed by the identifier of the container you want to start:
podman start 972c7c1db0c3
972c7c1db0c31a42ba4b41025078dfc6abb046f503aa413d6cca313068042041 
  1. At this point, if you run the podman ps -ap command, you should see that the status of the podman-nuxtjs-demo container is now Up:
podman ps -ap CONTAINER ID  IMAGE                                         COMMAND      CREATED            STATUS                        PORTS                   NAMES                POD 

ab5bd4810494  docker.io/library/postgres:11-alpine          postgres     7 minutes ago      Up 5 minutes ago             0.0.0.0:3000->3000/tcp  dreamy_jackson       d15a2abd9d5b 

972c7c1db0c3  quay.io/andreipope/podman-nuxtjs-demo:podman  npm run dev  14 minutes ago     Up 54 seconds ago             0.0.0.0:3000->3000/tcp  festive_yonath       d15a2abd9d5b 

6a5bc0360ae2  k8s.gcr.io/pause:3.1                                       14 minutes ago     Up 14 minutes ago             0.0.0.0:3000->3000/tcp  d15a2abd9d5b-infra   d15a2abd9d5b
  1. Lastly, let's top the podman_demo pod:
podman pod stop podman_demo
d15a2abd9d5bcb6f403515c0ed4dd4cb7df252a87591a88975b5573eb7f20900
  1. Enter the following command to make sure your Pod is stopped:
podman pod ps
POD ID         NAME             STATUS    CREATED          # OF CONTAINERS   INFRA ID 
d15a2abd9d5b   podman_demo      Stopped   17 minutes ago   3                 6a5bc0360ae2

Generate a Kubernetes Pod Spec with Podman

Podman can perform a snapshot of your container/Pod and generate a Kubernetes spec. This way, it makes it easier for you to orchestrate your containers with Kubernetes. For the scope of this section, we'll illustrate how to use Podman to generate a Kubernetes spec and deploy your Pod to Kubernetes.

  1. To create a Kubernetes spec for a container and save it into a file called podman-nuxtjs-demo.yaml, run the following podman generate kube command:
podman generate kube <CONTAINER_ID> > podman-nuxtjs-demo.yaml
  1. Let's take a look at what's inside the podman-nuxtjs-demo.yaml file:
cat podman-nuxtjs-demo.yaml


Shell
 




xxxxxxxxxx
1
53


1
# Generation of Kubernetes YAML is still under development!
2
#
3
# Save the output of this file and use kubectl create -f to import
4
# it into Kubernetes.
5
#
6
# Created with podman-1.6.4
7
 
          
8
 
          
9
```YAML
10
apiVersion: v1
11
kind: Pod
12
metadata:
13
  creationTimestamp: "2020-02-12T05:21:44Z"
14
  labels:
15
    app: objectiveneumann
16
  name: objectiveneumann
17
spec:
18
  containers:
19
  - command:
20
    - npm
21
    - run
22
    - dev
23
    env:
24
    - name: PATH
25
      value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
26
    - name: TERM
27
      value: xterm
28
    - name: HOSTNAME
29
    - name: container
30
      value: podman
31
    - name: NODE_VERSION
32
      value: 10.19.0
33
    - name: YARN_VERSION
34
      value: 1.21.1
35
    - name: NUXT_HOST
36
      value: 0.0.0.0
37
    - name: NUXT_PORT
38
      value: "3000"
39
    image: localhost/podman-nuxtjs-demo:podman
40
    name: objectiveneumann
41
    ports:
42
    - containerPort: 3000
43
      hostPort: 3000
44
      protocol: TCP
45
    resources: {}
46
    securityContext:
47
      allowPrivilegeEscalation: true
48
      capabilities: {}
49
      privileged: false
50
      readOnlyRootFilesystem: false
51
    tty: true
52
    workingDir: /usr/src/nuxt-app
53
status: {}



There is a lot of output here, but the parts we're interested in are:

  1. Edit the content of the podman-nuxtjs-demo.yaml file to the following:
Shell
 




xxxxxxxxxx
1
50


 
1
# Generation of Kubernetes YAML is still under development!
2
#
3
# Save the output of this file and use kubectl create -f to import
4
# it into Kubernetes.
5
#
6
# Created with podman-1.6.4
7
apiVersion: v1
8
kind: Pod
9
metadata:
10
  creationTimestamp: "2020-02-12T05:24:44Z"
11
  labels:
12
    app: podman-nuxtjs-demo
13
  name: podman-nuxtjs-demo
14
spec:
15
  containers:
16
  - command:
17
    - npm
18
    - run
19
    - dev
20
    env:
21
    - name: PATH
22
      value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
23
    - name: TERM
24
      value: xterm
25
    - name: HOSTNAME
26
    - name: container
27
      value: podman
28
    - name: NODE_VERSION
29
      value: 10.19.0
30
    - name: YARN_VERSION
31
      value: 1.21.1
32
    - name: NUXT_HOST
33
      value: 0.0.0.0
34
    - name: NUXT_PORT
35
      value: "3000"
36
    image: quay.io/andreipope/podman-nuxtjs-demo:podman
37
    name: objectiveneumann
38
    ports:
39
    - containerPort: 3000
40
      hostPort: 3000
41
      protocol: TCP
42
    resources: {}
43
    securityContext:
44
      allowPrivilegeEscalation: true
45
      capabilities: {}
46
      privileged: false
47
      readOnlyRootFilesystem: false
48
    tty: true
49
    workingDir: /usr/src/nuxt-app
50
status: {}



The above spec uses the address of our container image - quay.io/andreipope/podman-nuxtjs-demo:podman. Make sure you replace this with your address.

  1. Now, if your Quay.io repository is private, Kubernetes must authenticate with the registry to pull the image. Point your browser to http://quay.io, and then navigate to the Settings section of your repository. Select Generate Encrypted Password, and you'll be asked to type your password. From the sidebar on the left, select Kubernetes Secret to download your Kubernetes secrets file:

  1. Next, you must refer to this Kubernetes secret from the podman-nuxtjs-demo.yaml. You can do this by adding a field similar to the one below:
imagePullSecrets:    - name: andreipope-pull-secret

Note that the name of our Kubernetes secret is andreipope-pull-secret, but yours will be different.

At this point, your podman-nuxtjs-demo.yaml file should look something like the following:

Shell
 




xxxxxxxxxx
1
52


 
1
# Generation of Kubernetes YAML is still under development!
2
#
3
# Save the output of this file and use kubectl create -f to import
4
# it into Kubernetes.
5
#
6
# Created with podman-1.6.4
7
apiVersion: v1
8
kind: Pod
9
metadata:
10
  creationTimestamp: "2020-02-12T05:24:44Z"
11
  labels:
12
    app: podman-nuxtjs-demo
13
  name: podman-nuxtjs-demo
14
spec:
15
  containers:
16
  - command:
17
    - npm
18
    - run
19
    - dev
20
    env:
21
    - name: PATH
22
      value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
23
    - name: TERM
24
      value: xterm
25
    - name: HOSTNAME
26
    - name: container
27
      value: podman
28
    - name: NODE_VERSION
29
      value: 10.19.0
30
    - name: YARN_VERSION
31
      value: 1.21.1
32
    - name: NUXT_HOST
33
      value: 0.0.0.0
34
    - name: NUXT_PORT
35
      value: "3000"
36
    image: quay.io/andreipope/podman-nuxtjs-demo:podman
37
    name: objectiveneumann
38
    ports:
39
    - containerPort: 3000
40
      hostPort: 3000
41
      protocol: TCP
42
    resources: {}
43
    securityContext:
44
      allowPrivilegeEscalation: true
45
      capabilities: {}
46
      privileged: false
47
      readOnlyRootFilesystem: false
48
    tty: true
49
    workingDir: /usr/src/nuxt-app
50
  imagePullSecrets:
51
    - name: andreipope-pull-secret
52
status: {}



Create a Kubernetes Cluster with Kind (Optional)

Kind is a tool for running local Kubernetes clusters using Docker container "nodes". Follow the steps in this section if you don't have a running Kubernetes cluster:

Create a file called cluster.yaml with the following content:

kind create cluster --config cluster.yaml
# three node (two workers) cluster config 
kind: Cluster 
apiVersion: kind.x-k8s.io/v1alpha4 
nodes:
 - role: control-plane
 - role: worker
 - role: worker
  1. Apply the spec:
kind create cluster --config cluster.yaml
Shell
 




xxxxxxxxxx
1
10


 
1
Creating cluster "kind" ...
2
  Ensuring node image (kindest/node:v1.16.3) ��
3
  Preparing nodes ��
4
  Writing configuration ��
5
  Starting control-plane ��️
6
  Installing CNI ��
7
  Installing StorageClass ��
8
  Joining worker nodes ��
9
Set kubectl context to "kind-kind"
10
You can now use your cluster with:



This creates a Kubernetes cluster with a control plane and two worker nodes.

Deploying to Kubernetes

  1. Apply your Kubernetes pull secrets spec. Enter the kubectl create command specifying:


kubectl create -f andreipope-secret.yml --namespace=default
secret/andreipope-pull-secret created
  1. Now you're ready to apply the podman-nuxt-js-demo spec:
kubectl apply -f podman-nuxt-js-demo.yaml
pod/podman-nuxtjs-demo created
  1. Monitor the status of your installation with:
kubectl get pods
NAME               READY   STATUS              RESTARTS   AGE 
podman-nuxtjs-demo   0/1     ContainerCreating   0          85s
  1. You can retrieve more details about the status of your installation by entering the kubectl describe pod followed by the name of your Pod:
kubectl describe pod  podman-nuxtjs-demo
Shell
 




xxxxxxxxxx
1
59


1
Name:         podman-nuxtjs-demo
2
Namespace:    default
3
Priority:     0
4
Node:         kind-worker2/172.17.0.3
5
Start Time:   Wed, 12 Feb 2020 19:36:37 +0200
6
Labels:       app=podman-nuxtjs-demo
7
Annotations:  kubectl.kubernetes.io/last-applied-configuration:
8
                {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"creationTimestamp":"2020-02-12T05:24:44Z","labels":{"app":"podman-nuxtjs-dem...
9
Status:       Pending
10
IP:
11
IPs:          <none>
12
Containers:
13
  objectiveneumann:
14
    Container ID:
15
    Image:         quay.io/andreipope/podman-nuxtjs-demo:podman
16
    Image ID:
17
    Port:          3000/TCP
18
    Host Port:     3000/TCP
19
    Command:
20
      npm
21
      run
22
      dev
23
    State:          Waiting
24
      Reason:       ContainerCreating
25
    Ready:          False
26
    Restart Count:  0
27
    Requests:
28
      memory:  1Gi
29
    Environment:
30
      PATH:          /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
31
      TERM:          xterm
32
      HOSTNAME:
33
      container:     podman
34
      NODE_VERSION:  10.19.0
35
      YARN_VERSION:  1.21.1
36
      NUXT_HOST:     0.0.0.0
37
      NUXT_PORT:     3000
38
    Mounts:
39
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-rp6n5 (ro)
40
Conditions:
41
  Type              Status
42
  Initialized       True
43
  Ready             False
44
  ContainersReady   False
45
  PodScheduled      True
46
Volumes:
47
  default-token-rp6n5:
48
    Type:        Secret (a volume populated by a Secret)
49
    SecretName:  default-token-rp6n5
50
    Optional:    false
51
QoS Class:       Burstable
52
Node-Selectors:  <none>
53
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
54
                 node.kubernetes.io/unreachable:NoExecute for 300s
55
Events:
56
  Type    Reason     Age   From                   Message
57
  ----    ------     ----  ----                   -------
58
  Normal  Scheduled  57s   default-scheduler      Successfully assigned default/podman-nuxtjs-demo to kind-worker2
59
  Normal  Pulling    55s   kubelet, kind-worker2  Pulling image "quay.io/andreipope/podman-nuxtjs-demo:podman"



As an alternative, you can list events with the following command:

kubectl get events
Shell
 




xxxxxxxxxx
1
17


 
1
LAST SEEN   TYPE     REASON                    OBJECT                    MESSAGE
2
4m55s       Normal   RegisteredNode            node/kind-control-plane   Node kind-control-plane event: Registered Node kind-control-plane in Controller
3
4m37s       Normal   Starting                  node/kind-control-plane   Starting kube-proxy.
4
4m36s       Normal   NodeHasSufficientMemory   node/kind-worker          Node kind-worker status is now: NodeHasSufficientMemory
5
4m36s       Normal   NodeHasNoDiskPressure     node/kind-worker          Node kind-worker status is now: NodeHasNoDiskPressure
6
4m36s       Normal   NodeHasSufficientPID      node/kind-worker          Node kind-worker status is now: NodeHasSufficientPID
7
4m35s       Normal   RegisteredNode            node/kind-worker          Node kind-worker event: Registered Node kind-worker in Controller
8
4m15s       Normal   Starting                  node/kind-worker          Starting kube-proxy.
9
3m36s       Normal   NodeReady                 node/kind-worker          Node kind-worker status is now: NodeReady
10
4m34s       Normal   NodeHasSufficientMemory   node/kind-worker2         Node kind-worker2 status is now: NodeHasSufficientMemory
11
4m34s       Normal   NodeHasNoDiskPressure     node/kind-worker2         Node kind-worker2 status is now: NodeHasNoDiskPressure
12
4m34s       Normal   NodeHasSufficientPID      node/kind-worker2         Node kind-worker2 status is now: NodeHasSufficientPID
13
4m30s       Normal   RegisteredNode            node/kind-worker2         Node kind-worker2 event: Registered Node kind-worker2 in Controller
14
4m15s       Normal   Starting                  node/kind-worker2         Starting kube-proxy.
15
3m34s       Normal   NodeReady                 node/kind-worker2         Node kind-worker2 status is now: NodeReady
16
3m29s       Normal   Scheduled                 pod/podman-nuxtjs-demo    Successfully assigned default/podman-nuxtjs-demo to kind-worker2
17
3m27s       Normal   Pulling                   pod/podman-nuxtjs-demo    Pulling image "quay.io/andreipope/podman-nuxtjs-demo:podman"



  1. Wait a bit until the pod is created. Then, you can list all pods with:
kubectl get pods
NAME                 READY   STATUS    RESTARTS   AGE 
podman-nuxtjs-demo   1/1     Running   0          7m34s
  1. Now let's forward all requests made to http://localhost:3000 to port 3000 on the podman-nuxtjs-demo Pod:
kubectl port-forward pod/podman-nuxtjs-demo 3000:3000
Forwarding from 127.0.0.1:3000 -> 3000 
Forwarding from [::1]:3000 -> 3000 
Handling connection for 3000 
Handling connection for 3000 
Handling connection for 3000 
Handling connection for 3000 
Handling connection for 3000 
Handling connection for 3000 
Handling connection for 3000
  1. Point your browser to http://localhost:3000. If everything works well, you should see something like the following:


Congratulations on completing this tutorial, now you know enough to use Podman as a replacement for Docker. Stay tuned for our next tutorials where, amongst many other things, you'll learn how to use Buildah.
Thanks for reading!


This article was originally published on https://appfleet.com/blog/podman-for-docker-users/.

 

 

 

 

Top