Shivam Papat
Shivam Papat

Reputation: 530

Container name changes after system restart

I am starting and stopping container using systemd unit file service as.

Taking container name as hello

podman ps shows hello in output

  1. Auto generate unit file for hello

podman generate systemd --new --files --name hello

  1. The unit file contains

ExecStartPre=/bin/rm -f %t/%n.ctr-id

ExecStart=/usr/bin/podman run --cidfile=%t/%n.ctr-id --sdnotify=conmon --cgroups=no-conmon -d --hostname=first containerID

ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id

ExecStop=/usr/bin/podman stop --ignore --cidfile=%t/%n.ctr-id

  1. When I reboot system and check

    systemctl status container-hello

    I get status as Active: running

  2. But if I run podman ps -a , I get to see hello as inactive as well as another container added say hello2 as running.

  3. hello2 is associated with the unit file created in step 1 and hello is not.

I have used --hostname as suggested but I cannot see container with that name when checked with podman ps pr podman ps -a

Upvotes: 0

Views: 611

Answers (2)

Shivam Papat
Shivam Papat

Reputation: 530

What worked for me:

  1. I added --name parameter in the ExecStart label inside unit file as:

ExecStart=/usr/bin/podman run --cidfile=%t/%n.ctr-id --sdnotify=conmon --cgroups=no-conmon -d --name=container_name ID

  1. When podman auto generates unit file, it makes sure that once the container is stopped, it should be removed by,

ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id

I erased this line from the unit file.

Results:

  1. I can start /stop/re start container now without the container getting removed.
  2. When I restart my system (reboot), the container name remains same as it was before reboot. (name given in --name paramter)
  3. Container auto restarts with same name everytime.

Upvotes: 0

queeg
queeg

Reputation: 9412

From https://docs.podman.io/en/latest/markdown/podman-run.1.html: Podman generates a UUID for each container, and if a name is not assigned to the container with --name then it will generate a random string name. The name is useful any place you need to identify a container. This works for both background and foreground containers.

So you may want to edit your unit file to contain

ExecStart=/usr/bin/podman run ... --name hello

If that fixes the problem but the way you generate the unit should cover the name, maybe it is worth filing a bug for podman.

Upvotes: 1

Related Questions