docker ENTRYPOINT 上的多个命令 [英] Multiple commands on docker ENTRYPOINT

查看:97
本文介绍了docker ENTRYPOINT 上的多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建自定义 tcserver docker 映像.但是我在启动网络服务器和 tomcat 时遇到了一些问题.
据我所知,我应该使用 ENTRYPOINT 来运行我想要的命令.
问题是,是否可以使用 ENTRYPOINT 运行多个命令?
还是我应该创建一个小的 bash 脚本来启动所有内容?

基本上我想做的是:

ENTRYPOINT/opt/pivotal/webserver/instance1/bin/httpdctl start &&/opt/pivotal/webserver/instance2/bin/httpdctl start &&/opt/pivotal/pivotal-tc-server-standard/standard-4.0.1.RELEASE/tcserver start instance1 -i/opt/pivotal/pivotal-tc-server-standard &&/opt/pivotal/pivotal-tc-server-standard/standard-4.0.1.RELEASE/tcserver start instance2 -i/opt/pivotal/pivotal-tc-server-standard

但我不知道这是否是一种好的做法,或者是否可行.

解决方案

如果您想在入口点运行许多命令,最好的办法是创建一个 bash 文件.例如 commands.sh 像这样

#!/bin/bashmkdir/root/.sshecho "某事";光盘ls...

然后,在您的 DockerFile 中,将入口点设置为 commands.sh 文件(执行并运行您在其中的所有命令)

COPY commands.sh/scripts/commands.sh运行 [chmod"、+x"、/scripts/commands.sh"]入口点 [/scripts/commands.sh"]

之后,每次启动容器时,commands.sh 都会执行并运行您需要的所有命令.你可以看这里https://github.com/dangminhtruong/drone-chatwork

I'm trying to build a custom tcserver docker image. But I'm having some problems starting the webserver and the tomcat.
As far as I understand I should use ENTRYPOINT to run the commands I want.
The question is, is it possible to run multiple commands with ENTRYPOINT?
Or should I create a small bash script to start all?

Basically what I would like to do is:

ENTRYPOINT /opt/pivotal/webserver/instance1/bin/httpdctl start && /opt/pivotal/webserver/instance2/bin/httpdctl start && /opt/pivotal/pivotal-tc-server-standard/standard-4.0.1.RELEASE/tcserver start instance1 -i /opt/pivotal/pivotal-tc-server-standard && /opt/pivotal/pivotal-tc-server-standard/standard-4.0.1.RELEASE/tcserver start instance2 -i /opt/pivotal/pivotal-tc-server-standard

But I don't know if that is a good practice or if that would even work.

解决方案

In case you want to run many commands at entrypoint, the best idea is to create a bash file. For example commands.sh like this

#!/bin/bash
mkdir /root/.ssh
echo "Something"
cd tmp
ls
...

And then, in your DockerFile, set entrypoint to commands.sh file (that execute and run all your commands inside)

COPY commands.sh /scripts/commands.sh
RUN ["chmod", "+x", "/scripts/commands.sh"]
ENTRYPOINT ["/scripts/commands.sh"]

After that, each time you start your container, commands.sh will be execute and run all commands that you need. You can take a look here https://github.com/dangminhtruong/drone-chatwork

这篇关于docker ENTRYPOINT 上的多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆