Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mounted volume is empty inside container

I've got a docker-compose.yml like this:

db:   image: mongo:latest   ports:     - "27017:27017" server:   image: artificial/docker-sails:stable-pm2   command: sails lift   volumes:     - server/:/server   ports:     - "1337:1337"   links:     - db 

server/ is relative to the folder of the docker-compose.yml file. However when I docker exec -it CONTAINERID /bin/bash and check /server it is empty.

What am I doing wrong?

like image 597
Hedge Avatar asked Jul 26 '16 07:07

Hedge


People also ask

What does mounting a volume mean in docker?

The VOLUME command will mount a directory inside your container and store any files created or edited inside that directory on your hosts disk outside the container file structure, bypassing the union file system.

Can you mount a volume while building your docker image?

When building an image, you can't mount a volume. However, you can copy data from another image! By combining this, with a multi-stage build, you can pre-compute an expensive operation once, and re-use the resulting state as a starting point for future iterations.

Where are docker volumes mounted?

Volumes are stored in a part of the host filesystem which is managed by Docker ( /var/lib/docker/volumes/ on Linux).


2 Answers

Aside from the answers here, it might have to do with drive sharing in Docker Setting. On Windows, I discovered that drive sharing needs to be enabled.

In case it is already enabled and you recently changed your PC's password, you need to disable drive sharing (and click "Apply") and re-enable it again (and click "Apply"). In the process, you will be prompted for your PC's new password. After this process, run your docker command (run or compose) again enter image description here

like image 127
papigee Avatar answered Oct 02 '22 05:10

papigee


Try using:

volumes:   - ./server:/server 

instead of server/ -- there are some cases where Docker doesn't like the trailing slash.

like image 36
ldg Avatar answered Oct 02 '22 04:10

ldg