I prepare Dockerfile for my angular application, which looks like that:
FROM node:11.6.0-alpine AS builder
COPY . ./ToDoApp
WORKDIR /ToDoApp
RUN npm i
RUN $(npm bin)/ng build --prod
FROM nginx:1.15.8-alpine
COPY --from=builder /ToDoApp/dist/ToDoApp/ /usr/share/nginx/html
I use commands:
docker build --rm -t todoapp:latest .
docker run --rm -d -p 90:80/tcp todoapp:latest
and site was avaiable on available:90.
No I trying prepare docker-compose.yml which I use to run my website and other services. Everything is works except my website. I have no idea why it didn't work. I still get a message "todoapp exited with code 0".
My docker-compose.yaml:
services:
todoapp:
container_name: todoapp
restart: always
build:
context: ./ToDoApp
dockerfile: Dockerfile
ports:
- "4200:80"
volumes:
- .:/usr/share/nginx/html
Anyone can help me?
ng buildonly builds angular but doesn't actually serve it. Exited with 0 means that there was no error, it just ran successfully because it finished building. If you also have nginx service in your docker-compose you need to make sure to mount its html folder together with your own container.