简体   繁体   中英

How to put command of build docker container to dockerfile?

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
???

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 .

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

ie 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

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 eg, 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM