简体   繁体   English

如何使用 docker-compose 复制容器内的文件

[英]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最后,运行以下命令来构建新镜像并启动容器

  • docker-compose up -d --build docker-compose up -d --build

暂无
暂无

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

相关问题 Docker:docker-compose 将文件从容器复制到主机 - Docker: docker-compose copy files from container to host 如何在docker-machine中使用docker-compose将文件从docker容器复制到主机 - How to copy files from docker container to host using docker-compose in docker-machine 如何在 docker-compose 中的一个 docker 容器中添加选项 - how to add option in one docker container inside docker-compose 如何将本地文件共享到docker容器中使用docker-compose进行swarm - How to share local files to docker container In swarm with docker-compose 如何将文件复制到 Docker 卷并通过 docker-compose 使用该卷 - How to copy files to a Docker volume and use that volume with docker-compose 使用docker-compose时如何在容器内与主机用户一起修改卷文件 - How to modify volume files with host user inside container when using docker-compose docker-compose 在 Alpine 容器内 - docker-compose inside Alpine container 我可以在没有 bash 脚本的情况下使用 docker-compose 来检查容器,然后将文件从容器复制到主机吗? - Can I use docker-compose without a bash script to inspect a container then copy files to host from the container? 使用 Docker-compose 将文件复制到 Docker 容器中的 tomcat webapps 文件夹 - Copy files to the tomcat webapps folder in Docker container using Docker-compose docker-compose 和 powershell - 将文件复制到 Windows 容器中的“C:\\Program Files” - docker-compose and powershell - copy files into 'C:\Program Files' within Windows container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM