docker-compose,如何在容器启动后如何运行bash命令,而不覆盖图像码头中的CMD或入口点?
我只想重命名一些文件,而不覆盖 docker 拉入的 wordpress 图像内的命令。 在 docker-compose.yml 中,我尝试使用“命令”和“入口点”来运行 bash 命令,两者基本上都会中断图像内部发生的事情,并且全部失败。
I just want to rename a few files, without overriding the commands inside the wordpress image that the docker is pulling in.
Inside the docker-compose.yml I tried using 'command' and 'entrypoint' to run bash commands, both basically interrupt what's happening inside the image and it all fails.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有三种主要方法可以在容器开始之后运行命令:
docker exec -d somecontainer从命令行中使用一些命令
,cmd [“一些” ,“命令”]
,带有命令的dockerfile
如果这些文件都不适合您,则可能,您在做错了什么。一个常见的错误是在您的docker-compose文件中使用多个
命令
,就像:这是不起作用的,因为最后一个命令覆盖了上面的命令,您应该做的是condentate命令
:查看此问题。
编辑:我忘记包括的一件事是,上面的同样的行为对dockerfile中的 cmd 是正确的,您不能做到这一点:
取而代之的是,您应该像Docker-Compose一样加入命令:
但是,如果您有很多命令,这很无聊,因此替代方案是使用带有所需的所有命令的shell脚本并在Dockerfile中执行它:
请参阅此问题,
因为您没有提供任何代码,但您也可以使用
>运行命令将
重命名为最后一个命令(在CMD之前使用它)在您的Dockerfile中以在构建时间重命名这些文件(IMHO更有意义,因为当您时,这是您应该做的事情正在构建您的图像)。因此,如果您需要更多帮助,请也包括您的代码。you have three main ways to run a command after the container starts:
docker exec -d someContainer some command
from the command line,CMD ["some", "command"]
from your Dockerfilecommand: some command
from a docker-compose fileif none of these is working for you, probably, you are doing something wrong. A common mistake is using multiple
command
in your docker-compose file, like so:this doesn't work, because the last command overrides the commands above, what you should do is concatenate the commands:
take a look at this question.
edit: one thing i forgot to include is that the same behavior above is true to CMD in your Dockerfile, you can't do this:
instead, you should concatenate the commands, just like the docker-compose:
but this is very boring if you have a lot of commands, so an alternative is to use a shell script with all the commands you need and execute it in your Dockerfile:
see this question
As you haven't provided any code it's hard to say, but also, maybe you can use
RUN command to rename
as the last command(just before the CMD if you are using it) in your Dockerfile to rename these files at build time(what IMHO makes more sense because this is kind of thing you should do when you are building your images). So if you want more help, please, include your code too.