Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: --replace or else for "podman network create" and "podman volume create" #8842

Closed
dschier-wtd opened this issue Dec 27, 2020 · 8 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@dschier-wtd
Copy link

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind feature

Description

Creating new volumes or networks can be done via podman volume create <name> or podman network create <name>. This will fail, if <name> already exists. For volumes, one can workaround this issue, since podman volume run -v <name>:/foo will only create the volume, if it is not existing. For networks, this does not work.

It would be awesome to see some cli additions, so podman network create --replace <name> or podman network create --if-not.-exists <name> can be used.

Output of podman version:

podman version 2.2.1
@openshift-ci-robot openshift-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Dec 27, 2020
@rhatdan
Copy link
Member

rhatdan commented Dec 28, 2020

Not sure what your goal here is? Are you looking to have a script that runs multiple times but does not know if the network was already created?

Would podman network create foobar failing with an already EEXIST (17) satisfy your needs?

$ errno -l | grep -i exis
EEXIST 17 File exists

@dschier-wtd
Copy link
Author

The goal is quite easy. podman containers will be started with systemd. For me it is only natural to do the network and volume creation the same way, alongside the containers. This is currently not achievable, since ExecStart= will fail, if the network is already existing.

@rhatdan
Copy link
Member

rhatdan commented Dec 29, 2020

Couldn't you do something like

ExecStartPre=podman network inspect FOOBAR > /dev/null || podman network create FOOBAR

@dschier-wtd
Copy link
Author

dschier-wtd commented Dec 29, 2020

Sure, I can do this or provide a script or else.

It just feels like a missing feature/a workaround/inconsistent, since:

# This works and replaces existing pods with the same name
podman pod create --replace web

# This works and replaces existing containers with the same name
podman container run --name web01 --replace httpd:2

# This will fail, if net01 already exists
podman network create net01

# This will fail, if vol01 already exists
podman volume create vol01

# This will fail, if net01 does not exist
podman container run --name web01 --replace --network net01 httpd:2

# This works and creates vol01 on demand/if not existing
podman container create --volume vol01:/var/www/html httpd:2

@Luap99
Copy link
Member

Luap99 commented Dec 29, 2020

Note that replace is not the same as if not exists. Replace will always remove before creating the container/pod. If not exists will do nothing if it already exists. Deleting a network is not safe if other containers are using it so I think you want the if not exists behaviour.

@dschier-wtd
Copy link
Author

@Luap99 completely correct. This is how --volume currently works and I would appreciate to see the same for --network.

Having a proper switch for podman volume create or podman network create just seemed reasonable.

@Luap99
Copy link
Member

Luap99 commented Jan 16, 2021

I opened #8987 to add --if-not-exists to podman network create.

Luap99 pushed a commit to Luap99/libpod that referenced this issue Jan 17, 2021
If `--if-not-exists` is set `podman network create` will not error
if the a network with the same given name already exists.

This option is only supported for local podman client. Supporting
the remote client would require changes in the api endpoint.

This option can be used as `ExecStartPre` command in a systemd
service file. see containers#8842

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
@Luap99
Copy link
Member

Luap99 commented Jan 21, 2021

We now support podman network exists and podman volume exists commands. This allows for more flexible use cases.

@Luap99 Luap99 closed this as completed Jan 21, 2021
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

No branches or pull requests

4 participants