Overtronje
Overtronje

Reputation: 57

Docker-compose volume doesn't work as expected

I'm trying to mount a volume via docker-composer but after running docker-compose up the directory is empty.

Dockerfile

FROM alpine:3.8

COPY test.txt ./app/

docker-compose.yml

version: "3.7"

services:
  test:
    image: myrep/image:latest
    volumes:
      -  "./app/:/app/"

My procedure:

  1. Build docker image on client (docker build .)
  2. Push docker image to my registry (docker tag xxx myrep/image && docker push myrep/image)
  3. On the server I pull the image (docker pull myrep/image)
  4. Run docker-compose up (docker-compose up)
  5. Then when I look into the app folder there is no test.txt file

Any idea what I'm doing wrong?

Upvotes: 1

Views: 3165

Answers (2)

Mike Doe
Mike Doe

Reputation: 17624

You copied the file into the image, but when you start the container you overwrite it with your directory when mounting it.

If you want the file to be there don’t mount the volume.

You can verify this by running the image without a volume and executing:

docker-compose exec test ls -l /app

Upvotes: 5

May be you should try to add ./ before test.txt as it is not copying the file to the root directory Hope it will work for you

    FROM alpine:3.8
    COPY ./test.txt ./app/

Upvotes: 0

Related Questions