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?

Dragos Roban
  • 479
  • 2
  • 11
  • 20
  • 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.? – acran Mar 21 '21 at 16:23

5 Answers5

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
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/
Mustafa Güler
  • 884
  • 6
  • 11
0

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

chmod -R 777 /carrier
Do Trung Duc
  • 396
  • 3
  • 13
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.

Dragos Roban
  • 479
  • 2
  • 11
  • 20
-1

Remove the last /

volumes:
  - ./carrier:/var/local/Config
  • Doesn't work either. It doesn't copy the config file which is under /carrier. :( – Dragos Roban Mar 19 '21 at 10:05
  • 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. – Dragos Roban Mar 19 '21 at 10:15