I'm having trouble on trying to mount a volume to my docker container.
Here is my project structure
cloudRun
distService/
index.js
Dockerfile
package.json // THIS IS THE package.json FOR THE DOCKER IMAGE
package.json // THIS IS MY MAIN PROJECT package.json
In my main project package.json
I have the following scripts:
"docker-run": "./scripts/docker/docker-run.sh",
"docker-inspect": "docker exec -ti hello-world sh" // THIS IS USED TO INSPECT THE RUNNING CONTAINER
docker-run.sh
// STOPS ALL CONTAINERS
// REMOVES ALL CONTAINERS
// REMOVES ALL IMAGES
// BUILDS A NEW IMAGE FROM SCRATCH
docker build --tag hello-world:latest ./cloudRun
// TRYING TO RUN THE CONTAINER WITH A MOUNTED /distService VOLUME
docker run --name hello-world -p 3000:3000 -v //distService:/distService hello-world:latest
This is the Dockerfile
:
FROM node:12-slim
WORKDIR /
COPY ./package.json ./package.json
RUN npm install
ENTRYPOINT npm start
It's all working. Except for the fact that the container is seeing /distService
as an empty folder.
I know this because when I open a new terminal window and run:
npm run docker-inspect
I get to enter the folders and ls
them. And this is what I'm getting: there is a distService
folder, but the ls
command comes back empty. PS: I did a ls
on node_modules
just to show that it works and the distService
is indeed empty.
QUESTION
When I pass -v //folder:/folder
, what is the source folder relative to? How can I be sure that I'm picking the right folder?
Environment:
Windows 10.
Docker for Windows installed
Docker Engine v19.03.13
UPDATE
I ran the container and inspected it with: docker inspect <CONTAINER_ID>
to see what folder is being mounted. But it didn't help much. This is what came back:
"HostConfig": {
"Binds": [
"//distService/:/distService/"
],
// OTHER STUFF
"Mounts": [
{
"Type": "bind",
"Source": "/distService", // WHAT IS THIS PATH RELATIVE TO ?
"Destination": "/distService",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
This is what I had to do to make it work.
Basicallly I had to put the full absolute path starting from
c:/
.Full command:
I had the idea after I found this on the official docs: