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

前端 未结 5 2007
醉话见心
醉话见心 2020-12-12 15:35

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

相关标签:
5条回答
  • 2020-12-12 15:42

    To override the default entrypoint, use entrypoint option. To pass the arguments use command.

    Here is the example of replacing bash with sh in ubuntu image:

    version: '3'
    services:
      sh:
        entrypoint: /bin/sh
        command: -c "ps $$(echo $$$$)"
        image: ubuntu
        tty: true
      bash:
        entrypoint: /bin/bash
        command: -c "ps $$(echo $$$$)"
        image: ubuntu
        tty: true
    

    Here is the output:

    $ docker-compose up   
    Starting test_sh_1                ... done
    Starting 020211508a29_test_bash_1 ... done
    Attaching to test_sh_1, 020211508a29_test_bash_1
    sh_1    |   PID TTY      STAT   TIME COMMAND
    sh_1    |     1 pts/0    Ss+    0:00 /bin/sh -c ps $(echo $$)
    020211508a29_test_bash_1 |   PID TTY      STAT   TIME COMMAND
    020211508a29_test_bash_1 |     1 pts/0    Rs+    0:00 ps 1
    
    0 讨论(0)
  • 2020-12-12 15:45

    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
    
    0 讨论(0)
  • 2020-12-12 15:52

    I was facing the same issue with jenkins ssh slave 'jenkinsci/ssh-slave'. However, my case was a 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"]
    
    0 讨论(0)
  • 2020-12-12 15:58

    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
    
    0 讨论(0)
  • 2020-12-12 16:00

    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.

    0 讨论(0)
提交回复
热议问题