Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple folders in one docker volume

Tags:

docker

volume

I have two folders, let's say /etc/folder1 and /etc/folder2. I want to map them both in the same docker volume. So that I have these two folders in the root of my volume. Is that possible?

What I want is:

/etc/folder1 
/etc/folder2
and then /vol1/folder1 and /vol1/folder2
like image 498
fuuman Avatar asked Sep 27 '16 07:09

fuuman


People also ask

Can a docker container have multiple volumes?

Docker has multiple options to persist and share data for a running container. However, we may need more than one file storage for a running container, for example, to create backups or grant different access. Or for the same container, we may need to add named volumes and bind them to specific paths.

Does docker volume create directory?

The file or directory is referenced by its absolute path on the host machine. By contrast, when you use a volume, a new directory is created within Docker's storage directory on the host machine, and Docker manages that directory's contents. The file or directory does not need to exist on the Docker host already.

What are the two types of docker volumes?

Docker volumes are used to persist data from within a Docker container. There are a few different types of Docker volumes: host, anonymous, and, named.

Do docker volumes have size limit?

In the current Docker version, there is a default limitation on the Docker container storage of 10Gb.


2 Answers

Yes:

> mkdir ~/vol1
> mkdir ~/vol2
> touch ~/vol1/file1
> touch ~/vol2/file2
> docker run -it -v ~/vol1:/vol1 -v ~/vol2:/vol2 ubuntu find / -name file*
/vol2/file2
/vol1/file1
...

You can mount multiple volumes into a container, and you can event mount individual files from the host into the container using volumes.

like image 129
Elton Stoneman Avatar answered Sep 30 '22 19:09

Elton Stoneman


i think it is possible with:

php:
    image: imagename
    volumes:
        -/etc/folder1:/folder1
        -/etc/folder2:/folder2

you have to create folder1 & folder2 in your Dockerfile.

...
RUN  mkdir folder1 folder2
...
like image 29
Gabbax0r Avatar answered Sep 30 '22 18:09

Gabbax0r