Can I override a folder in a Docker image with a volume from host?

463 Views Asked by At

Given a Dockerfile like this:

WORKDIR /

COPY ./folder ./folder

# OTHER COMMANDS...

On my dev environment I would like to override the ./folder that was copied to the image, by using the real ./folder on my machine, so I can use nodemon from the image and make it hot reload with changes.

So if I run this image like this:

docker run OTHER_STUFF -v ./folder:/folder IMAGE_NAME

Is this the correct approach to override a folder that exists on the image, with an external folder?

1

There are 1 best solutions below

0
On

Yes, this is the correct way. Only one detail: you must specify the full absolute path on the host i.e.:

docker run OTHER_STUFF -v /full/path/to/folder:/folder IMAGE_NAME

If you want to use relative paths you should use docker-compose.