Dragos Roban
Dragos Roban

Reputation: 609

How to copy files inside container with docker-compose

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?

Upvotes: 5

Views: 23956

Answers (5)

Muhammad Laique Sario
Muhammad Laique Sario

Reputation: 185

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

Upvotes: 8

Dragos Roban
Dragos Roban

Reputation: 609

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.

Upvotes: 0

Do Trung Duc
Do Trung Duc

Reputation: 406

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

chmod -R 777 /carrier

Upvotes: 0

Mustafa Güler
Mustafa Güler

Reputation: 1014

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/

Upvotes: 1

user4093955
user4093955

Reputation:

Remove the last /

volumes:
  - ./carrier:/var/local/Config

Upvotes: -1

Related Questions