[英]How to copy files inside container with docker-compose
I have a simple image that runs a jar file.我有一个运行 jar 文件的简单图像。 That jar file inside the image needs a special configuration file in order to run.
镜像中的 jar 文件需要一个特殊的配置文件才能运行。
In the location with the docker-compose.yml I have a folder named "carrier" and under this folder I have that file.在 docker-compose.yml 的位置,我有一个名为“carrier”的文件夹,在这个文件夹下我有那个文件。
The docker-compose.yml: docker-compose.yml:
version: "3.3"
services:
web:
image: "myimage:1.80.0.0"
ports:
- "61003:61003"
volumes:
- ./carrier:/var/local/Config/
When I hit docker-compose up
it complains that the file is not there, so it doesn't copy it.当我点击
docker-compose up
它抱怨文件不存在,所以它不会复制它。 If I do another option like I did in the.sh command, something like this:如果我像在 .sh 命令中那样执行另一个选项,则如下所示:
volumes:
- ./carrier:/var/local/Config/:shared
It complains about another error:它抱怨另一个错误:
C:\Tasks\2246>docker-compose up
Removing 2246_web_1
Recreating 1fbf5d2bcea4_2246_web_1 ... error
ERROR: for 1fbf5d2bcea4_2246_web_1 Cannot start service web: path /host_mnt/c/Tasks/2246/carrier is mounted on / but it is not a shared mount
Can someone please help me?有人可以帮帮我吗?
Remove the last /
删除最后一个
/
volumes:
- ./carrier:/var/local/Config
You can use Dockerfile if it does not copy.如果不复制,您可以使用 Dockerfile。
Dockerfile; Dockerfile;
FROM image
COPY files /var/local/Config/
EXPOSE 61003
Docker-compose; Docker-compose;
version: "3.3"
services:
web:
build: . (path contains Dockerfile)
ports:
- "61003:61003"
volumes:
- ./carrier:/var/local/Config/
I'm not sure but you can try to set full access permissions for all user to /carrier:我不确定,但您可以尝试将所有用户的完全访问权限设置为 /carrier:
chmod -R 777 /carrier
Thanks all for all your answers.感谢大家的所有回答。 Seems like finally docker warned me with some comparisons over the windows files vs Linux files when building the image.
似乎最终 docker 在构建图像时警告我对 windows 文件与 Linux 文件进行了一些比较。 (Not with docker compose but with Dockerfile).
(不使用 docker 撰写,但使用 Dockerfile)。
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
Tried it on linux and works.在 linux 上进行了尝试,并且可以正常工作。
Copy the files using Dockerfile, use below;使用 Dockerfile 复制文件,在下面使用;
FROM myimage:1.80.0.0
RUN mkdir -p /var/local/Config/
COPY carrier /var/local/Config/
EXPOSE 61003
docker-compose.yml docker-compose.yml
version: "3.3"
services:
web:
build:
dockerfile: Dockerfile
context: '.'
ports:
- "61003:61003"
In the end, run below command to build new image and start container最后,运行以下命令来构建新镜像并启动容器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.