Docker Community Forums

Share and learn in the Docker community.

Passing command line arguments from a file


(Golfercwu) #1

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/redis.co
-p 6379:6379
-d
redis
redis-server --appendonly yes /usr/local/etc/redis.conf`

Make "--user `whoami`" the default for "docker run"
(Doncicuto) #2

Hi!
maybe you could use docker compose (https://docs.docker.com/compose/overview/) 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.

Cheers!


(David Maze) #3

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
#!/bin/sh
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.)


(Golfercwu) #4

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