GNU/Linux >> Linux Esercitazione >  >> OpenSuse

Come installare e utilizzare Podman in OpenSUSE Leap 15.3

Podman integra Buildah e Skopeo offrendo un'esperienza simile alla riga di comando Docker:consentendo agli utenti di eseguire container standalone (non orchestrati). E Podman non richiede un demone per eseguire container e pod, quindi possiamo facilmente dire addio ai grandi demoni grassi. Non ci sono demoni in background che fanno cose, e questo significa che Podman può essere integrato nei servizi di sistema tramite systemd .

In questa guida impareremo come installare Podman in OpenSUSE Leap.

Post correlati

  • Come installare e usare Podman in Debian 11
  • Come installare e utilizzare Podman in Rocky Linux/Alma Linux/Centos 8
  • Come installare e utilizzare Podman in Fedora 34/35
  • Come installare e configurare la finestra mobile in Rocky Linux/Centos 8
  • Introduzione a Docker Componi con esempi
  • Docker come agente di compilazione:esegui le build Jenkins su Docker

Prerequisiti

Per seguire, assicurati di avere quanto segue:

  • Un server/workstation OpenSUSE LEAP aggiornato
  • Accesso root o Utente con accesso sudo
  • Accesso a Internet

Indice dei contenuti

  1. Assicurarsi che il server sia aggiornato
  2. Installazione di Podman
  3. Esempi di riga di comando
  4. Contenitore persistente di Runa postgres
  5. Gestire i container come servizi di sistema tramite systemd e Podman

1. Garantire che il server sia aggiornato

Usa questo comando per assicurarti che i nostri pacchetti server siano aggiornati

sudo zypper ref
sudo zypper update -y

Assicuriamoci che i pacchetti comuni siano installati

sudo zypper install -y vim

2. Installazione di Podman

Podman è disponibile nei repository predefiniti per OpenSUSE. Installalo usando questo comando:

sudo zypper install -y podman

Questo comando installerà Podman e anche le sue dipendenze.

È tutto. Ora possiamo giocare con Podman.

3. Esempi di riga di comando

Esploriamo l'esecuzione di OpenSUSE Leap Container utilizzando podman.

Nella finestra mobile useremmo questo comando per eseguire un contenitore OpenSUSE Leap:

docker run -it opensuse/leap:15.3 sh

L'operazione avrà esito negativo poiché non esiste docker comando sulla mia macchina OpenSUSE. Possiamo sostituire docker con podman:

podman run -it opensuse/leap:15.3 sh

Eseguiamo alcuni comandi per confermare che funzioni come previsto:

~> podman run -it opensuse/leap:15.3 sh
Trying to pull registry.opensuse.org/opensuse/leap:15.3...
Getting image source signatures
Copying blob 7bc46307c67f done
Copying config 09d5e2cf44 done
Writing manifest to image destination
Storing signatures
sh-4.4# whoami
root
sh-4.4# cat /etc/os-release
NAME="openSUSE Leap"
VERSION="15.3"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.3"
PRETTY_NAME="openSUSE Leap 15.3"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.3"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"
sh-4.4#

Per controllare lo stato del contenitore, usa podman ps comando

~> podman ps -a
CONTAINER ID  IMAGE                                     COMMAND  CREATED         STATUS                     PORTS   NAMES
eaa09408b382  registry.opensuse.org/opensuse/leap:15.3  sh       53 seconds ago  Exited (0) 13 seconds ago          priceless_curran

Per eliminare il contenitore, utilizza podman rm :

~> podman rm eaa09408b382
eaa09408b382ceb33a4696fed282e76df5130abf556b085ddc199eb30af54c8c

Per elencare le immagini:

~> podman images
REPOSITORY                           TAG     IMAGE ID      CREATED      SIZE
registry.opensuse.org/opensuse/leap  15.3    09d5e2cf44af  2 weeks ago  111 MB

Possiamo eliminare l'immagine utilizzando l'immagine podman image rm comando:

~> podman image rm opensuse/leap:15.3
Untagged: registry.opensuse.org/opensuse/leap:15.3
Deleted: 09d5e2cf44af39c62b803e65991d700d8300dc34d82ff03c9cf359b9e092177a

Da quanto sopra, possiamo confermare che il comando podman utilizza la stessa sintassi della finestra mobile

4. Esegui un contenitore persistente Postgres

Successivamente, esploriamo come eseguire un contenitore persistente. In questo esempio, eseguiremo un contenitore Postgres 14 e monteremo i dati postgres su un volume locale in modo che possa persistere i riavvii. Poiché i contenitori sono effimeri, i dati andranno persi se non salviamo in un volume locale.

Estrarre docker.io/library/postgres:14.0-alpine immagine

~> podman image rm opensuse/leap:15.3
Untagged: registry.opensuse.org/opensuse/leap:15.3
Deleted: 09d5e2cf44af39c62b803e65991d700d8300dc34d82ff03c9cf359b9e092177a
[email protected]:~> podman pull docker.io/library/postgres:14.0-alpine
Trying to pull docker.io/library/postgres:14.0-alpine...
Getting image source signatures
Copying blob 82e9eb77798b done
Copying blob 5034a66b99e6 done
Copying blob 3da258773353 done
Copying blob c6b2245b2f36 done
Copying blob a0d0a0d46f8b done
Copying blob ccd761727716 done
Copying blob 028554d3b6cc done
Copying blob 2c7ee7bc69e8 done
Copying config 87440f4e7f done
Writing manifest to image destination
Storing signatures
87440f4e7f9e60607dc11a4f0590a1c69b3a1c075211df478e22b0c27fb263e6

Conferma le immagini

~> podman images
REPOSITORY                  TAG          IMAGE ID      CREATED      SIZE
docker.io/library/postgres  14.0-alpine  87440f4e7f9e  2 weeks ago  198 MB

Ispeziona l'immagine con

$ podman inspect 87440f4e7f9e

Impostiamo una cartella che gestirà i dati di Postgres una volta avviato il nostro contenitore:

$ mkdir -p ~/apps/postgres/data

Eseguilo

podman run -d \
    -p 5432:5432 \
    -v ~/apps/postgres/data:/var/lib/postgresql/data \
    -e POSTGRES_PASSWORD=Sup3rSecre7 \
    -e POSTGRES_USER=citizix_user \
    -e POSTGRES_DB=citizix_db \
    docker.io/library/postgres:14.0-alpine

Questo è il mio risultato

~> podman run -d \
>     -p 5432:5432 \
>     -v ~/apps/postgres/data:/var/lib/postgresql/data \
>     -e POSTGRES_PASSWORD=Sup3rSecre7 \
>     -e POSTGRES_USER=citizix_user \
>     -e POSTGRES_DB=citizix_db \
>     docker.io/library/postgres:14.0-alpine
1607081ed241073e20e6186543c1882e977f2a91c9c061ccdd36a3e357051a44

Verifica i processi:

~> podman ps
CONTAINER ID  IMAGE                                   COMMAND   CREATED         STATUS             PORTS                   NAMES
1607081ed241  docker.io/library/postgres:14.0-alpine  postgres  11 seconds ago  Up 10 seconds ago  0.0.0.0:5432->5432/tcp  happy_jang

Conferma i log del contenitore con questo. Puoi vedere che sta inizializzando il db

~> podman logs 1607081ed241 | head
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok

Connettiamoci al database ed eseguiamo alcune operazioni

$ podman exec -it 1607081ed241 /bin/bash
bash-5.1# psql -U citizix_user -d citizix_db;
psql (14.0)
Type "help" for help.

citizix_db=# select version();
                                                   version
--------------------------------------------------------------------------------------------------------------
 PostgreSQL 14.0 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.3.1_git20210424) 10.3.1 20210424, 64-bit
(1 row)

citizix_db=#

Quindi esploriamo l'uccisione e la rimozione del contenitore. Possiamo usare podman kill per fermare il contenitore. Questo fermerà il contenitore, ma sarà ancora lì. Usa podman ps -a  elencare. Per rimuoverlo completamente, quindi podman rm -f .

~> podman kill 1607081ed241
1607081ed241073e20e6186543c1882e977f2a91c9c061ccdd36a3e357051a44

~> podman ps -a
CONTAINER ID  IMAGE                                   COMMAND   CREATED             STATUS                       PORTS                   NAMES
1607081ed241  docker.io/library/postgres:14.0-alpine  postgres  About a minute ago  Exited (137) 15 seconds ago  0.0.0.0:5432->5432/tcp  happy_jang

~> podman rm -f 1607081ed241
1607081ed241073e20e6186543c1882e977f2a91c9c061ccdd36a3e357051a44

5. Gestire i container come servizi di sistema tramite systemd e Podman

Possiamo gestire i container Podman tramite systemd. Creiamo un systemd file di risorse per la gestione del container postgres che abbiamo appena creato sopra.

Crea un file podman postgres:

sudo vim /etc/systemd/system/postgres-podman.service

Aggiungi questo contenuto

[Unit]
Description=Custom Postgres Podman Container
After=network.target

[Service]
Type=simple
TimeoutStartSec=5m
ExecStartPre=-/usr/bin/podman rm -f postgrespodman

ExecStart=/usr/bin/podman run \
    -p 5432:5432 \
    -v /home/ec2-user/apps/postgres/data:/var/lib/postgresql/data \
    -e POSTGRES_PASSWORD=Sup3rSecre7 \
    -e POSTGRES_USER=citizix_user \
    -e POSTGRES_DB=citizix_db \
    docker.io/library/postgres:14.0-alpine

ExecReload=-/usr/bin/podman stop postgrespodman
ExecReload=-/usr/bin/podman rm postgrespodman
ExecStop=-/usr/bin/podman stop postgrespodman
Restart=always
RestartSec=30

[Install]

Quindi possiamo ricaricare il systemd catalogare e avviare il servizio:

sudo systemctl daemon-reload
sudo systemctl start postgres-podman

Conferma lo stato del servizio

~> sudo systemctl status postgres-podman
● postgres-podman.service - Custom Postgres Podman Container
     Loaded: loaded (/etc/systemd/system/postgres-podman.service; static)
     Active: active (running) since Mon 2021-11-15 05:40:34 UTC; 12s ago
    Process: 23658 ExecStartPre=/usr/bin/podman rm -f postgrespodman (code=exited, status=1/FAILURE)
   Main PID: 23687 (podman)
      Tasks: 12 (limit: 4587)
     CGroup: /system.slice/postgres-podman.service
             ├─23687 /usr/bin/podman run -p 5432:5432 -v /home/ec2-user/apps/postgres/data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=Sup3rSecre7 -e POSTG>
             └─23828 /usr/bin/conmon --api-version 1 -c 8a18a63727ecd19d03710544e3e7ee9241e886d9fed45c1f25e29547ab61d600 -u 8a18a63727ecd19d03710544e3e7ee924>

Nov 15 05:40:35 ip-10-2-40-188 podman[23687]: 2021-11-15 05:40:35.477 UTC [1] LOG:  starting PostgreSQL 14.0 on x86_64-pc-linux-musl, compiled by gcc (Alpine>
Nov 15 05:40:35 ip-10-2-40-188 podman[23687]: 2021-11-15 05:40:35.478 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
Nov 15 05:40:35 ip-10-2-40-188 podman[23687]: 2021-11-15 05:40:35.478 UTC [1] LOG:  listening on IPv6 address "::", port 5432
Nov 15 05:40:35 ip-10-2-40-188 podman[23687]: 2021-11-15 05:40:35.482 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
Nov 15 05:40:35 ip-10-2-40-188 podman[23687]: 2021-11-15 05:40:35.486 UTC [22] LOG:  database system was interrupted; last known up at 2021-11-15 05:35:02 UTC
Nov 15 05:40:35 ip-10-2-40-188 podman[23687]: 2021-11-15 05:40:35.497 UTC [22] LOG:  database system was not properly shut down; automatic recovery in progre>
Nov 15 05:40:35 ip-10-2-40-188 podman[23687]: 2021-11-15 05:40:35.499 UTC [22] LOG:  redo starts at 0/16FAD98
Nov 15 05:40:35 ip-10-2-40-188 podman[23687]: 2021-11-15 05:40:35.499 UTC [22] LOG:  invalid record length at 0/16FADD0: wanted 24, got 0
Nov 15 05:40:35 ip-10-2-40-188 podman[23687]: 2021-11-15 05:40:35.499 UTC [22] LOG:  redo done at 0/16FAD98 system usage: CPU: user: 0.00 s, system: 0.00 s, >
Nov 15 05:40:35 ip-10-2-40-188 podman[23687]: 2021-11-15 05:40:35.509 UTC [1] LOG:  database system is ready to accept connections

Abbiamo appena impostato un servizio di sistema personalizzato basato su un container gestito tramite Podman!

Conclusione

In questa guida siamo riusciti a esplorare come installare Podman nel nostro server OpenSUSE Leap.


OpenSuse
  1. Come installare PostgreSQL e phpPgAdmin su OpenSUSE Leap 42.1

  2. Come installare Mongodb 5 in Opensuse Leap 15.3

  3. Come installare Mysql Server 8 su OpenSUSE Leap 15.3

  4. Come installare e configurare Redis 6 su OpenSUSE Leap 15.3

  5. Come installare Erlang su Opensuse Leap 15.3

Come installare Skype su openSUSE Leap

Come installare TeamViewer 12 su openSUSE Leap 42.2

Come installare Dropbox su openSUSE Leap 42.2

Come installare RabbitMQ in OpenSUSE Leap 15.3

Come installare Google Chrome su openSUSE Leap 15

Come installare PHP 8.0 su openSUSE 15 Leap