How to copy files inside container with docker-compose
Asked Answered
F

5

5

I have a simple image that runs a jar file. That jar file inside the image needs a special configuration file in order to run.

In the location with the docker-compose.yml I have a folder named "carrier" and under this folder I have that file.

The 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. If I do another option like I did in the .sh command, something like this:

       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?

Flavor answered 19/3, 2021 at 9:48 Comment(1)
Please add the exact error message you're getting! When I hit docker-compose up it complains that the file is not there: i.e. does docker-compose complain or your app inside the running container? Is it actually complaining that the file/directory does not exist or that it can not be accessed - i.e. may also be due to wrong permissions etc.?Borstal
Z
8

Copy the files using Dockerfile, use below;

FROM myimage:1.80.0.0
RUN mkdir -p /var/local/Config/
COPY carrier /var/local/Config/
EXPOSE 61003

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
Zollverein answered 22/3, 2021 at 12:17 Comment(0)
G
1

You can use Dockerfile if it does not copy.

Dockerfile;

FROM image

COPY files /var/local/Config/

EXPOSE 61003

Docker-compose;

version: "3.3"
services:
    web:
        build: . (path contains Dockerfile)
        ports:
            - "61003:61003"
        volumes:
            - ./carrier:/var/local/Config/
Granth answered 19/3, 2021 at 18:8 Comment(0)
M
0

I'm not sure but you can try to set full access permissions for all user to /carrier:

chmod -R 777 /carrier
Mastigophoran answered 20/3, 2021 at 10:52 Comment(0)
F
0

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. (Not with docker compose but with 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.

Flavor answered 22/3, 2021 at 10:6 Comment(0)
K
-1

Remove the last /

volumes:
  - ./carrier:/var/local/Config
Kilmer answered 19/3, 2021 at 10:0 Comment(2)
Doesn't work either. It doesn't copy the config file which is under /carrier. :(Flavor
Although I tried with a different image which doesn't complain about the file and it is copied in the location. Don't know why my application complains about the missing file.Flavor

© 2022 - 2024 — McMap. All rights reserved.