I have an angular library that I build like so:
ng build my-library -- --watch and a dist directory gets generated.
I have a dummy angular app to test my library, in package.json:
docker:start : ng serve --host 0.0.0.0 --poll 1
When I run in my terminal, during development, I run the build in one terminal and the app in another. As I make changes, the build picks them up, and once the new library is built, the service takes the changes and I see them in the browser.
I'm trying to recreate this in Docker like so:
FROM node:10-alpine
WORKDIR /app
EXPOSE 4200
# Install Angular/CLI to use `ng`
RUN npm install -g @angular/cli
# My Application
COPY ./package*.json ./
RUN npm install
# Build ./dist/my-library
COPY ./ ./
RUN cd ./projects/my-library && npm run build
CMD ["npm","run","docker:start"]
My docker-compose.yml:
version: '3'
services:
app:
container_name: 'app'
build:
context: .
dockerfile: Dockerfile.dev
ports:
- '4200:4200'
volumes:
- /app/node_modules
- .:/app
I want to be able to run docker-compose up and do development like I do in the multiple terminals.
If you want to emulate multiple terminals, you can just run multiple 'services' in docker-compose:
version: '3'
services:
app:
container_name: 'app'
build:
context: .
dockerfile: Dockerfile.dev
ports:
- '4200:4200'
volumes:
- /app/node_modules
- .:/app
lib:
container_name: 'lib'
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- /app/node_modules
- .:/app
command: sh -c 'ng build my-library -- --watch'
Here is an example of a app/test docker-compose definition that I commonly use:
version: '3.7'
services:
web:
image: node:12-alpine
volumes:
- .:/src/app:cached
ports:
- 4200:4200
working_dir: /src/app
command: /bin/sh -c "npm install && npm run start-docker"
tests:
image: node:12-alpine
volumes:
- .:/src/app:cached
working_dir: /src/app
command: /bin/sh -c "npm install && npm run test:watch"