运行中的容器

引言

Fedora CoreOS发货时同时安装了码头和Podman。这一页解释了如何使用系统单位来启动和停止集装箱与波德曼。

配置示例

下面的Butane配置代码片段将系统d hello.service配置为运行Busybox。

使用system d和podman运行Busybox的示例
variant: fcos
version: 1.4.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

正在运行etcd

ETCD不是作为Fedora CoreOS的一部分发货的。要使用它,请将其作为容器运行,如下所示。

用于设置单节点等的Butane配置
variant: fcos
version: 1.4.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

了解更多信息

请参阅 Etcd文档 有关在容器中运行etcd以及如何设置多节点etcd的更多信息。