1

I have script: docker run -it -p 4000:4000 bitgosdk/express:latest --disablessl -e test how to put this command to dockerfile with arguments?

FROM bitgosdk/express:latest
EXPOSE 4000
???
AbrA
  • 434
  • 1
  • 6
  • 19
  • so the command is just `--disablessl -e test` ? What is the output of `ps -ef` inside your running container? – mchawre Jan 04 '21 at 05:54

3 Answers3

2

Gone through your Dockerfile contents.

The command running inside container is:

/ # ps -ef | more
PID   USER     TIME  COMMAND
    1 root      0:00 /sbin/tini -- /usr/local/bin/node /var/bitgo-express/bin/bitgo-express --disablessl -e test

The command is so because the entrypoint set in the Dockerfile is ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/node", "/var/bitgo-express/bin/bitgo-express"] and the arguments --disablessl -e test are the one provided while running docker run command.

The --disablessl -e test arguments can be set inside your Dockerfile using CMD:

CMD ["--disablessl", "-e","test"]

New Dockerfile:

FROM bitgosdk/express:latest
EXPOSE 4000
CMD ["--disablessl", "-e","test"]

Refer this to know the difference between entrypoint and cmd.

mchawre
  • 10,744
  • 4
  • 35
  • 57
1

You don't. This is what docker-compose is used for.

i.e. create a docker-compose.yml with contents like this:

version: "3.8"

services:
  test:
    image: bitgodsdk/express:latest
    command: --disablessl -e test
    ports:
    - "4000:4000"

and then execute the following in a terminal to access the interactive terminal for the service named test.

docker-compose run test

Chris Becke
  • 34,244
  • 12
  • 79
  • 148
  • 1
    I generally consider Compose `command:` an override, and I'd consider setting a default Dockerfile `CMD` preferable. – David Maze Jan 04 '21 at 11:58
  • 1
    True. But if that is the only thing requring a Dockerfile, then better to keep it as a compose-file override and skip the hassle of working with a custom image. – Chris Becke Jan 04 '21 at 12:24
0

Even if @mchawre's answer seems to directly answer OP's question "syntactically speaking" (as a Dockerfile was asked), a docker-compose.yml is definitely the way to go to make a docker run command, as custom as it might be, reproducible in a declarative way (YAML file).

Just to complement @ChrisBecke's answer, note that the writing of this YAML file can be automated. See e.g., the FOSS (under MIT license) https://github.com/magicmark/composerize

FTR, the snippet below was automatically generated from the following docker run command, using the accompanying webapp https://composerize.com/:

docker run -it -p 4000:4000 bitgosdk/express:latest

version: '3.3'
services:
    express:
        ports:
            - '4000:4000'
        image: 'bitgosdk/express:latest'

I omitted the CMD arguments --disablessl -e test on-purpose, as composerize does not seem to support these extra arguments. This may sound like a bug (and FTR a related issue is opened), but meanwhile it might just be viewed as a feature, in line of @DavidMaze's comment

ErikMD
  • 13,377
  • 3
  • 35
  • 71