How do I mount a host directory as a volume in docker compose

0 votes

I'm dockerizing a development environment, and I'd like to be able to livereload my modifications without having to rebuild the docker images. Because redis is one of my app's requirements, and I appreciate being able to link a redis container, I'm using docker compose.

In my docker-compose.yml, I have two containers defined:

node:
  build: ./node
  links:
    - redis
  ports:
    - "8080"
  env_file:
    - node-app.env

redis:
  image: redis
  ports:
    - "6379"

I've gone as far as adding a volume to my node app's dockerfile, but how do I mount the host's directory in the volume so that all of my live code updates are reflected in the container?

My current Dockerfile is as follows:

# Set the base image to Ubuntu
FROM    node:boron

# File Author / Maintainer
MAINTAINER Amin Shah Gilani <amin@gilani.me>

# Install nodemon
RUN npm install -g nodemon

# Add a /app volume
VOLUME ["/app"]

# TODO: link the current . to /app

# Define working directory
WORKDIR /app

# Run npm install
RUN npm install

# Expose port
EXPOSE  8080

# Run app using nodemon
CMD ["nodemon", "/app/app.js"]

My project is like this:

/
- docker-compose.yml
- node-app.env
- node/
  - app.js
  - Dockerfile.js
Apr 28, 2022 in Docker by Abhijeet
• 180 points

edited 5 days ago 10 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP