简体   繁体   English

了解Dockerfile和docker run之间ENTRYPOINT / CMD顺序的差异

[英]Understanding the difference in sequence of ENTRYPOINT/CMD between Dockerfile and docker run

Docker noob here... Docker noob在这里...

I am trying to build and run an IBM DataPower container from a Dockerfile, but it doesn't seem to work the same as when just running docker run and passing the same parameters in the terminal. 我正在尝试从Dockerfile构建和运行IBM DataPower容器,但是它似乎与仅运行docker run并在终端中传递相同参数时的工作方式不同。

This works ( docker run ) 这有效( docker run

docker run -it \
  -v $PWD/config:/drouter/config \
  -e DATAPOWER_ACCEPT_LICENSE=true \
  -e DATAPOWER_INTERACTIVE=true \
  -e DATAPOWER_WORKER_THREADS=4 \
  -p 9090:9090 \
  --name mydatapower \
  ibmcom/datapower

... the key part being that it mounts the ./config folder and the custom configuration is picked up by datapower running in the container. ...关键部分是它安装了./config文件夹,并且容器中运行的datapower接受了自定义配置。

This doesn't ( Dockerfile ) 这不是( Dockerfile

Dockerfile: Dockerfile:

FROM ibmcom/datapower

ENV DATAPOWER_ACCEPT_LICENSE=true
ENV DATAPOWER_INTERACTIVE=true
ENV DATAPOWER_WORKER_THREADS=4

EXPOSE 9090

COPY config/auto-startup.cfg /drouter/config/auto-startup.cfg

Build: 建立:

docker build -t local/datapower .

Run: 跑:

docker run -it \
  -p 9090:9090 \
  --name mydatapower local/datapower

The problem is that DataPower doesn't pick up the auto-startup.cfg file, so the additional config options doesn't get used. 问题在于,DataPower不会拾取auto-startup.cfg文件,因此不会使用其他配置选项。 I know the source file path is correct because if I misspell the file name docker throws an error. 我知道源文件路径是正确的,因为如果我拼错了文件名,docker会抛出错误。

I have a theory that it might be running the inherited ENTRYPOINT or CMD before the config file is available. 我有一个理论,在配置文件可用之前,它可能正在运行继承的ENTRYPOINT或CMD。 I don't know how to test or prove this. 我不知道如何测试或证明这一点。 I don't know what the ENTRYPOINT or CMD is because the inherited image is not open source and I can't figure out how to find it. 我不知道ENTRYPOINT或CMD是什么,因为继承的图像不是开源的,我不知道如何找到它。

Does that seem likely? 看来有可能吗?

UPDATE: 更新:

The content of the auto-startup.cfg is: auto-startup.cfg的内容为:

top; co

ssh

web-mgmt
  admin enabled
  port 9090
exit

It simply enables the DataPower WebGUI. 它只是启用了DataPower WebGUI。

The output when running it in the commandline with: 在命令行中使用以下命令运行时的输出:

docker run -it -v $PWD/config:/drouter/config -v $PWD/local:/drouter/local -e DATAPOWER_ACCEPT_LICENSE=true -e DATAPOWER_INTERACTIVE=true -e DATAPOWER_WORKER_THREADS=4 -p 9091:9090 --name myconfigureddatapower ibmcom/datapower`

...contains this: ...包含以下内容:

20170908T121729.015Z [0x8100006e][system][notice] : Executing startup configuration.
20170908T121729.970Z [0x00350014][mgmt][notice] web-mgmt(WebGUI-Settings): tid(303): Operational state up

...but with Dockerfile it doesn't. ...但是使用Dockerfile却没有。 That's why I think the config files may be copied into place too late. 这就是为什么我认为配置文件可能复制到位太晚。

I've tried adding CMD ["/bin/drouter"] to the end of my Dockerfile to no avail. 我尝试将CMD ["/bin/drouter"]到我的Dockerfile末尾无济于事。

I have tested your Dockerfile and it seems to be working. 我已经测试了您的Dockerfile,它似乎正在工作。 My auto-startup.cfg file is copied in the proper location and when I launch the container it's reading the file. 我的auto-startup.cfg文件已复制到正确的位置,当我启动容器时,它正在读取文件。

I get this output: 我得到以下输出:

[root@ip-172-30-2-164 tmp]# docker run  -ti -p 9090:9090  test
20170908T123728.818Z [0x8040006b][system][notice] logging target(default-log): Logging started.
20170908T123729.067Z [0x804000fe][system][notice] : Container instance UUID: 36bcca0e-6139-4694-91b0-2b7b66c3a498, Cores: 4, vCPUs: 4, CPU model: Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz, Memory: 16049.1MB, Platform: docker, OS: dpos, Edition: developers-limited, Up time: 0 minutes
20170908T123729.071Z [0x8040001c][system][notice] : DataPower IDG is on-line.
20170908T123729.071Z [0x8100006f][system][notice] : Executing default startup configuration.
20170908T123729.416Z [0x8100006d][system][notice] : Executing system configuration.
20170908T123729.417Z [0x8100006b][mgmt][notice] domain(default): tid(8143): Domain operational state is up.
708f98be1390
Unauthorized access prohibited.
20170908T123731.239Z [0x806000dd][system][notice] cert-monitor(Certificate Monitor): tid(399): Enabling Certificate Monitor to scan once every 1 days for soon to expire certificates
20170908T123731.552Z [0x8100006e][system][notice] : Executing startup configuration.
20170908T123732.436Z [0x8100003b][mgmt][notice] domain(default): Domain configured successfully.
20170908T123732.449Z [0x00350014][mgmt][notice] web-mgmt(WebGUI-Settings): tid(303): Operational state up
login: 

To check that your file has been copied to the container you can run docker run -ti local/datapower sh to enter the container and then check the content of /drouter/config/ . 要检查文件是否已复制到容器中,可以运行docker run -ti local/datapower sh进入容器,然后检查/drouter/config/

Your base image command is: CMD ["/bin/drouter"] you can check it running docker history ibmcom/datapower . 您的基本映像命令是: CMD ["/bin/drouter"]您可以在运行docker history ibmcom/datapower检查它。

UPDATE: 更新:

The drouter user in the container must be able to read the auto-startup.cfg file. 容器中的drouter用户必须能够读取auto-startup.cfg文件。 You have 2 options: 您有2个选择:

  • set your local auto-startup.cfg with the proper permissions ( chmod 644 config/autostart.cfg ). 使用适当的权限( chmod 644 config/autostart.cfg )设置本地auto-startup.cfg
  • or add these line in the Dockerfile so drouter can read the file: 或在Dockerfile中添加以下行,以便drouter可以读取文件:

     USER root RUN chown drouter /drouter/config/auto-startup.cfg USER drouter 

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

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