How to put command of build docker container to dockerfile?

走远了吗. 提交于 2021-02-10 14:14:45

问题


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

回答1:


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.




回答2:


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




回答3:


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…



来源:https://stackoverflow.com/questions/65558209/how-to-put-command-of-build-docker-container-to-dockerfile

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