Docker Community Forums

Share and learn in the Docker community.

Default parameters to docker run

#1

Hello,

Short description:
I’d like to add default parameters to a docker run command, so they are always passed when docker run is executed. Is it possible ?

Reasons:
Docker containers are instenciated by a Condor scheduler and I’d like to bind GPU devices to the docker container via the --device /dev/nvidia0:/dev/nvidia0 like settings. These parameters are not passed by the invoking Condor binary, so I’m wondering whether they could be defined as some default.

Thanks for any help in advance,
Gergely

(Ove "Lime" Lindström) #2

Looks like a suitable task for a function.

I have a number of functions defined in my .bash_profile, like the docker-clean. It looks like this:

function docker-clean {
    docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
    docker rm $(docker ps -qa --no-trunc --filter "status=exited")
}

You could also use a docker-compose.yml and define your devices there instead and then use docker-compose or docker stack deploy to run it.

See https://docs.docker.com/compose/compose-file/#devices

#3

Thanks for the quick reply !

The problem is that “docker run bla bla bla” is called by another program that I cannot modify. So defining another function would not really help. As such I cannot use docker-compose or docker stack,

Do you see any other solution ?
Thanks,
Gergo

(Metin Y.) #5

Why would you even use Condor? It seems like it has it’s own declarative configuration, which restricts what actualy can be done.

If you have no control about how Condor creates/runs the container, there is no solution for this.
Raise a change request for Condor to handle the required functionality or don’t use it at all!

#6

Hi !
Thanks, yes Condor change request has already been sent and they are working on it, however I though that there could be a possible workaround on the docker side as well, since I don’t know how long the Condor fix will take !

Thanks anyway for everybody’s answer !
Gergely

1 Like
#7

Hi !
Just to let you know, that I found a solution which partially solve my original problem. It does not allow to pass generic default arguments but it allows to make GPU devices visible for the container without passing --device switches.

So
1.) installing Nvidia’s docker additions


and
2.) setting the default ‘runtime’ to nvidia in /etc/docker/daemon.json
3.) and setting NVIDIA_VISIBLE_DEVICES = all as environment variable (in Dockerfile )

makes the container to see all the GPUs without adding extra parameters to docker run / start.

thanks anyway for the helps,
Gergely

1 Like