简体   繁体   English

如何将构建 docker 容器的命令放入 dockerfile?

[英]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?我有脚本: docker run -it -p 4000:4000 bitgosdk/express:latest --disablessl -e test how to put this command to dockerfile with ZDBC11CAA5BDA99F77E6FB4DBD7

FROM bitgosdk/express:latest
EXPOSE 4000
???

Gone through your Dockerfile contents .浏览您的Dockerfile 内容

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.该命令之所以如此,是因为 Dockerfile 中设置的入口点是ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/node", "/var/bitgo-express/bin/bitgo-express"]和 arguments --disablessl -e test是在运行docker run命令时提供的。

The --disablessl -e test arguments can be set inside your Dockerfile using CMD : --disablessl -e test arguments 可以使用CMD在您的 Dockerfile 中设置:

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

New Dockerfile :新 Dockerfile :

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

Refer this to know the difference between entrypoint and cmd .请参阅此内容以了解入口点和 cmd 之间的区别

You don't.你没有。 This is what docker-compose is used for.这就是 docker-compose 的用途。

ie create a docker-compose.yml with contents like this:即创建一个docker-compose.yml ,其内容如下:

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.然后在终端中执行以下命令以访问名为 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). 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声明方式( YAML文件)。

Just to complement @ChrisBecke's answer , note that the writing of this YAML file can be automated.只是为了补充@ChrisBecke 的答案,请注意这个 YAML 文件的编写可以自动化。 See eg, the FOSS (under MIT license) https://github.com/magicmark/composerize参见例如 FOSS(根据 MIT 许可) 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/ : FTR,下面的代码片段是使用随附的 webapp https://composerize.com/从以下docker run命令自动生成的:

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.我故意省略了CMD arguments --disablessl -e test ,因为composerize似乎不支持这些额外的 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这听起来像是一个错误(和 FTR相关的问题已打开),但同时它可能只是被视为一个功能,符合@DavidMaze 的评论......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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