2

maybe it's a stupid question but, i would like to know how can i bring the data,folders and code FROM my container in MY desktop to work with my IDE with docker-compose, is it possible?

Thank you in advance to everyone!

kri-dev
  • 699
  • 2
  • 7
  • 12

1 Answers1

-1

You can access data inside your container from your local machine using docker volume.

Run your container with binding docker volume with your local file system like this:

docker run --name=<name> -d -v <local_directory>:<directory_inside_container> <image>

for instance, you have nginx container and you want to access container logs on local, you can do something like this:

docker run --name=nginx -d -v ~/nginxlogs:/var/log/nginx -p 5000:80 nginx

where ~/nginxlogs is directory on your local, while /var/log/nginx is the directory inside container.

Now you can access container logs in nginxlogs directory on local.

For docker-compose.yml add volume tag like this:

volumes:
    - ~/nginxlogs:/var/log/nginx
Rezwan
  • 1,203
  • 1
  • 7
  • 22
  • Thank you for you reply, with docker-compose is it possible? – kri-dev Dec 16 '20 at 13:27
  • I edited the answer to add volume tag using docer-compose.yml – Rezwan Dec 16 '20 at 13:35
  • 1
    Note: this technique mounts the local folder ~/nginxlogs into the container - if any files already existed in the container's /var/log/nginx folder at the time that the container starts, those files are not visible in ~/nginxlogs. Furthermore, those files are no longer available in the container either, as docker overlays the ~/nginxlogs with the container's /var/log/nginx directory. – user1279887 Sep 30 '21 at 13:30
  • This will NOT create a reverse bind volume like the question asks for. This will create a normal bind volume: a blank folder on the host machine called `~/nginxlogs` and blast away any files already in `/var/log/nginx` inside the docker container. This answer is not only misleading but dangerous as it will delete data inside the container. The real answer is that it's not possible: https://stackoverflow.com/questions/45788253/ – Michael Currie Jan 01 '23 at 19:48