0

I have a folder called 'Transfer'. During the execution of my program, new folders with files can be created in the 'Transfer' folder.

How do I dynamically transfer all new created file folders in Docker to my PC?

I tried to do something like this, but it doesn't work:

In the docker-compose.yml file for my transfer service, I added a volume called files:

    transfer:
        build: ./transfer
        ports:
            - 6666:6666
        volumes:
            - ./:/files

./ is a folder on the host, it is next to docker-compose.yml, new folders with files from my Docker volume called files should appear here /files - volume in Docker

At the end of docker-compose.yml I created this volume files:

volumes:
  files:
  • If you need files to be stored directly on the host, Docker's filesystem isolation might be working against you, and it might be easier to run the program outside a container. Also see [Docker: Copying files from Docker container to host](https://stackoverflow.com/questions/22049212/docker-copying-files-from-docker-container-to-host). – David Maze Jun 09 '22 at 20:03

1 Answers1

0

You say at the start of your post that the folder in the container is called 'Transfer'. That's the folder you need to map to a folder on your host machine.

If the Transfer folder is at the root of the file system, i.e. /Transfer, you can do

transfer:
    build: ./transfer
    ports:
        - 6666:6666
    volumes:
        - ./:/Transfer

Then the . directory on the host and the /Transfer directory in the container will in effect be the same. Any changes done to one of them will be visible in the other.

You don't need the volume definition you have at the bottom of your post.

Hans Kilian
  • 18,948
  • 1
  • 26
  • 35
  • should it all be displayed dynamically? because I run my program, and I create in the `Transfer` folder for example `user/file.txt` and in the folder with `docker-compose.yml` I didn’t have a folder with the file `user/file.txt` – pizzaman Jun 09 '22 at 18:45
  • If the full path of the file you create in the container is `/Transfer/user/file.txt`, then you should see a `user` directory in your current directory on the host with a `file.txt` file in it. The Linux file system is case sensitive, so it's important that you create the file in `/Transfer` with a capital 'T'. – Hans Kilian Jun 09 '22 at 18:49
  • I did everything as you said, but I still don't see a directory `user` with a `file.txt` file in it next to `docker-compose.yml` – pizzaman Jun 09 '22 at 19:01