cbdeveloper
cbdeveloper

Reputation: 31465

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

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?

Upvotes: 0

Views: 629

Answers (1)

acran
acran

Reputation: 8998

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.

Upvotes: 1

Related Questions