How to pass arguments to entrypoint in docker-compose.yml

匿名 (未验证) 提交于 2019-12-03 02:49:01

问题:

I use this image: dperson/samba

The image is defining it's own entrypoint and I do not want to override it.

I need to pass arguments to the entrypoint, easy with docker only:

docker run ... dperson/samba arg1 arg2 arg3 

But how to do it with docker_compose.yml ?

Right now I use as a workaround:

command: samba.sh arg1 arg2 arg3 

But it is not satisfying as I force the redefinition of the entrypoint.

回答1:

The command clause does work as @Karthik says above.

As a simple example, the following service will have a -inMemory added to its ENTRYPOINT when docker-compose up is run.

version: '2' services:   local-dynamo:     build: local-dynamo     image: spud/dynamo     command: -inMemory 


回答2:

Whatever is specified in the command in docker-compose.yml should get appended to the entrypoint defined in the Dockerfile, provided entrypoint is defined in exec form in the Dockerfile.

If the EntryPoint is defined in shell form, then any CMD arguments will be ignored.



回答3:

You can use docker-compose run instead of docker-compose up and tack the arguments on the end. For example:

docker-compose run dperson/samba arg1 arg2 arg3 

If you need to connect to other docker containers, use can use --service-ports option:

docker-compose run --service-ports dperson/samba arg1 arg2 arg3 


回答4:

I was facing same issue with jenkins ssh slave 'jenkinsci/ssh-slave', however my case was bit complicated because it was necessary to pass an argument which contained spaces. I've managed to do it like below (entrypoint in dockerfile is in exec form):

command: ["some argument with space which should be treated as one"] 

Hope this helps. Thanks.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!