Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Last active October 20, 2023 09:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cecilemuller/00c3f079b621cee7a821600a56d5d6c7 to your computer and use it in GitHub Desktop.
Save cecilemuller/00c3f079b621cee7a821600a56d5d6c7 to your computer and use it in GitHub Desktop.
Docker Compose Watch

Example for compose watch:

  • "watch" requires a "build" section
  • files created at runtime in the host get copied to the container
  • files deleted in the host aren't deleted in the container
  • files created in the container at build time aren't copied back to the host
  • files created in the container at runtime aren't copied back to the host
  • you'd still need a "volume" if the host must access files generated in the container
name: example-watch
services:
web:
image: example-watch-web
build:
context: ./app/
dockerfile_inline: |
FROM node:lts
WORKDIR /app
COPY src/ ./src/
COPY package.json watch.mjs ./
RUN npm install
CMD ["node", "./watch.mjs"]
develop:
watch:
- path: app/
target: /app/
action: sync
ignore:
- node_modules
- path: app/package.json
action: rebuild
{
// VSCode settings for the Docker extension:
// https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker
"docker.commands.composeUp": "docker-compose ${configurationFile} watch",
"docker.commands.composeUpSubset": "${composeCommand} ${profileList} ${configurationFile} watch ${detached} ${build} ${serviceList}",
"docker.commands.composeDown": "${composeCommand} ${configurationFile} down --volumes --rmi local",
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment