Docker Community Forums

Share and learn in the Docker community.

Passing command line arguments from a file

Beginner’s questions: I have this long line docker command (and I think it would only get longer as time goes on)

docker run --name myredis -v /mydata/redis:/data -v /mysrc/python/config/redis.conf:/usr/local/etc/redis.conf -p 6379:6379 -d redis redis-server --appendonly yes /usr/local/etc/redis.conf

Is there a way pass the command line arguments from a file? eg

docker run --args-from-file /usr/local/runcmd.txt

and runcmd.txt would look like:

--name myredis
-v /mydata/redis:/data
-v /mysrc/python/config/redis.conf:/usr/local/etc/
-p 6379:6379
redis-server --appendonly yes /usr/local/etc/redis.conf`

maybe you could use docker compose ( as an alternative?

Although it’s supposed to be used for multi-container applications you may use it for a service using only one container. You can set your volumes, ports… in YAML sintax and use that file to start your container.


You could write that (single) long line into a file; put the magic line #!/bin/sh as the first line of the file, chmod +x it, and it’s a shell script.

$ cat start-redis
docker run ... /usr/local/etc/redis.conf
$ chmod +x start-redis
$ ./start-redis

(The Docker Compose suggestion is also an excellent one; this might be easier in the short term.)

Thanks, yeah, using a shell script will do, still, maintaining a pure parameter file is better than a script, I guess

Hi @golfercwu, did you find a better solution for this?

doncicuto actualy suggested a better solution: declare your configuration with a docker-compose.yml.

docker-compose has build in support for env-files, can resolve system variables in place and extend configurations using multiple docker-compose.yml.

If you are not open to it yet: don’t worry, eventualy you will get there :wink:

Just to mention it: you could always use make and encapsulate the parsing and starting within the file. professionel setups end up using makefiles combined with swarm/kubernetes configurations, where configurations can be rendered using envsubst or a real template engine.