简体   繁体   English

重命名Docker容器中的文件

[英]Rename file in docker container

I'm having a weird Error when i try to run a simple script on docker container on redhat machine, this is the Docker file 当我尝试在Redhat机器上的Docker容器上运行一个简单的脚本时出现一个奇怪的错误,这是Docker文件

From tomcat:7.0.70-jre7
ENV CLIENTNAME geocontact
ADD tomcat-users.xml /usr/local/tomcat/conf/
ADD app.war /usr/local/tomcat/webapps/
COPY app.sh /

ENTRYPOINT ["/app.sh"] ENTRYPOINT [“ /app.sh”]

and app.sh is the script that cause the problem "only on redhat" 而app.sh是导致问题“仅在redhat上”的脚本

#!/bin/bash
set -e
mv /usr/local/tomcat/webapps/app.war /usr/local/tomcat/webapps/client1.war
catalina.sh run

and the error message : 和错误消息:

mv cannot move '/usr/local/tomcat/webapps/app.war to a subdirectory of itself, '/usr/local/tomcat/webapps/client1.war' mv无法将'/usr/local/tomcat/webapps/app.war移至其自身的子目录'/usr/local/tomcat/webapps/client1.war'

a screenshot for the error and this only on redhat, i run the same image on ubuntu and centos with no problems. 该错误的屏幕截图,并且仅在redhat上,我在ubuntu和centos上运行相同的图像没有问题。

You can split your command in 2 commands : 您可以将命令分为2个命令:

cp /usr/local/tomcat/webapps/app.war /usr/local/tomcat/webapps/client1.war
rm /usr/local/tomcat/webapps/app.war

In your Dockerfile: ADD fileA fileB . 在您的Dockerfile中: ADD fileA fileB That will rename fileA to fileB at the moment of image creation. 这将重命名fileAfileB在图像创作的时刻。

you can edit file inside container and commit changes without buiding image. 您可以在容器内编辑文件并提交更改而无需添加图片。

docker commit existing_containername commited_image_name 码头工人提交现存的容器名称commited_image_name

then run container with new for example 然后用new运行容器

docker run --name tomcat -td commited_image_name docker run --name tomcat -td commited_image_name

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

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