0

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?

7
  • It seems your Dockerfile doesn't run an actual webserver, ng build only 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. Commented Feb 2, 2020 at 13:55
  • How can I do this? Commented Feb 2, 2020 at 14:17
  • Actually I noticed that you have nginx image in your Dockerfile. And you do copy the files to the right place apparently. But I am not sure now does nginx actually start when you run this container? You can try the solution Talha Junaid suggested. Commented Feb 2, 2020 at 14:25
  • I tired but not helped :( Commented Feb 2, 2020 at 14:27
  • How do you run your docker-compose? Commented Feb 2, 2020 at 14:45

1 Answer 1

1

If you would like to keep your container running in detached mode, you need to run something in the foreground. An easy way to do this is to tail the /dev/null device as the CMD or ENTRYPOINT command of your Docker image.

Add the following as the last step in your docker file

CMD tail -f /dev/null

http://bigdatums.net/2017/11/07/how-to-keep-docker-containers-running/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.