docker-py icon indicating copy to clipboard operation
docker-py copied to clipboard

Allow different values for user_nsmode

Open pferreir opened this issue 4 months ago • 1 comments

create(...) currently allows only host as UsernsMode. This seems to make sense as docker only allows this as an option. However, podman supports a few others. I assume this package should be able to interact with other docker-compatible APIs, and in that case it would make sense that we can set this parameter differently. Right now, the only workaround I've found was to use the low level API as such:

host_config = api_client.create_host_config(
    binds={
        socket_dir: {'bind': '/var/run/postgresql', 'mode': 'rw'},
        data_dir: {'bind': '/var/lib/postgresql/data', 'mode': 'rw'},
    }
)

# kind of hacky, right?
host_config['UsernsMode'] = 'keep-id'

container_config = api_client.create_container(
    image=POSTGRES_IMAGE,
    name=CONTAINER_NAME,
    user=f'{os.getuid()}:{os.getgid()}',
    host_config=host_config,
    environment={'POSTGRES_USER': 'postgres', 'POSTGRES_PASSWORD': 'postgres', 'POSTGRES_DB': db_name},
)

pferreir avatar Aug 18 '25 14:08 pferreir

I already implemented that in https://github.com/docker/docker-py/pull/3230

bauen1 avatar Sep 16 '25 14:09 bauen1