在Docker文件中添加脚本,以在容器启动时启动。

huangapple go评论76阅读模式
英文:

Adding script in Docker File that starts when the container starts

问题

我一直在尝试为我的Java应用编写Docker文件。我该如何在Docker文件中添加"start_service.sh",以便在Docker容器启动运行时执行该文件。

英文:

I have been trying to write the docker file for my Java application. How i can add start_service.sh in Docker file which will execute when the docker container starts running.

答案1

得分: 0

可以使用 ENTRYPOINT Docker 命令来实现此目的,它将在容器启动时运行脚本。
示例:

FROM ...
...
COPY start_service.sh start_service.sh
ENTRYPOINT ["sh", "./start_service.sh"]

在这种情况下,脚本 start_service.sh 将在容器启动时执行。

英文:

You can use ENTRYPOINT docker command for this purpose, it will run the script on container start.
Example:

FROM ...
...
COPY start_service.sh start_service.sh
ENTRYPOINT ["sh", "./start_service.sh"]

In this case, the script start_service.sh will be executed on the container start.

答案2

得分: 0

这可能有助于解决问题

...
COPY start_service.sh start_service.sh
ENTRYPOINT ["./start_service.sh"]
...

https://docs.docker.com/engine/reference/builder/

英文:

this may help u solve the problem

...
COPY start_service.sh start_service.sh
ENTRYPOINT ["./start_service.sh"]
...

https://docs.docker.com/engine/reference/builder/

huangapple
  • 本文由 发表于 2020年4月9日 23:29:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/61124676.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定