Esecuzione di container

Introduzione

Fedora CoreOS include sia lo strumento CLI docker (fornito tramite [Moby](https://mobyproject.org/)) che [podman](https://podman.io). Questa pagina spiega come utilizzare le unità systemd per avviare e arrestare i container con podman.

Esempio di configurazione

Il seguente frammento di configurazione Butane configura il servizio systemd hello.service per eseguire [busybox](https://www.busybox.net).

You may be able to use local file references to systemd units instead of inlining them. See Using butane’s --files-dir Parameter to Embed Files for more information.
Example for running busybox using systemd and podman
variant: fcos
version: 1.6.0
systemd:
  units:
    - name: hello.service
      enabled: true
      contents: |
        [Unit]
        Description=MyApp
        After=network-online.target
        Wants=network-online.target

        [Service]
        TimeoutStartSec=0
        ExecStartPre=-/bin/podman kill busybox1
        ExecStartPre=-/bin/podman rm busybox1
        ExecStartPre=/bin/podman pull busybox
        ExecStart=/bin/podman run --name busybox1 busybox /bin/sh -c "trap 'exit 0' INT TERM; while true; do echo Hello World; sleep 1; done"

        [Install]
        WantedBy=multi-user.target
Example for running busybox using Podman Quadlet

[Podman Quadlet](https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html) è una funzionalità inclusa in Podman che consente di avviare contenitori tramite systemd utilizzando un generatore systemd. L’esempio seguente è lo stesso hello.service mostrato in precedenza, ma distribuito tramite la funzionalità Podman Quadlet.

variant: fcos
version: 1.6.0
storage:
  files:
    - path: /etc/containers/systemd/hello.container
      contents:
        inline: |
          [Unit]
          Description=Hello Service
          Wants=network-online.target
          After=network-online.target

          [Container]
          ContainerName=busybox1
          Image=docker.io/busybox
          Exec=/bin/sh -c "trap 'exit 0' INT TERM; while true; do echo Hello World; sleep 1; done"

          [Install]
          WantedBy=multi-user.target

Running etcd

etcd is not shipped as part of Fedora CoreOS. To use it, run it as a container, as shown below.

Butane config for setting up single node etcd
variant: fcos
version: 1.6.0
systemd:
  units:
    - name: etcd-member.service
      enabled: true
      contents: |
        [Unit]
        Description=Run single node etcd
        After=network-online.target
        Wants=network-online.target

        [Service]
        ExecStartPre=mkdir -p /var/lib/etcd
        ExecStartPre=-/bin/podman kill etcd
        ExecStartPre=-/bin/podman rm etcd
        ExecStartPre=-/bin/podman pull quay.io/coreos/etcd
        ExecStart=/bin/podman run --name etcd --volume /var/lib/etcd:/etcd-data:z --net=host quay.io/coreos/etcd:latest /usr/local/bin/etcd --data-dir /etcd-data --name node1 \
                --initial-advertise-peer-urls http://127.0.0.1:2380 --listen-peer-urls http://127.0.0.1:2380 \
                --advertise-client-urls http://127.0.0.1:2379 \
                --listen-client-urls http://127.0.0.1:2379 \
                --initial-cluster node1=http://127.0.0.1:2380

        ExecStop=/bin/podman stop etcd

        [Install]
        WantedBy=multi-user.target

For more information

See the etcd documentation for more information on running etcd in containers and how to set up multi-node etcd.