I have a development environment I'm dockerizing and I would like the ability to livereload my changes without having to rebuild docker images. I'm using docker compose because redis is one of my app's dependencies and I like being able to link a redis container
I have two containers defined in my docker-compose.yml
:
node:
build: ./node
links:
- redis
ports:
- "8080"
env_file:
- node-app.env
redis:
image: redis
ports:
- "6379"
I've gotten to the point in my node
app's dockerfile where I add a volume, but how do I mount the the host's directory in the volume so that all my live edits to the code are reflected in the container?
Here's my current Dockerfile:
# 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 looks like this:
/
- docker-compose.yml
- node-app.env
- node/
- app.js
- Dockerfile.js
Checkout their documentation
From the looks of it you could do the following on your docker-compose.yml
It was two things:
I added the volume in
docker-compose.yml
:I moved the
npm install && nodemon app.js
pieces into aCMD
becauseRUN
adds things to the Union File System, and my volume isn't part of UFS.There's a few options
Short Syntax
Using the
host : guest
format you can do any of the following:Long Syntax
As of docker-compose v3.2 you can use long syntax which allows the configuration of additional fields that can be expressed in the short form such as
mount type
(volume, bind or tmpfs) andread_only
.Check out https://docs.docker.com/compose/compose-file/#long-syntax-3 for more info.