0

So I am trying to start up an server that has:

  • a mongodb container
  • a backend container
  • a client container

Both server containers require me to run yarn start at the end. However, when I run this in the dockerfile the image never stops being built as the yarn start command technically never stops running.

The client requires the backend to be up already, and the backend requires the mongodb db instance to be up.

How do I get this server running in docker compose?

Here is my backend dockerfile

 FROM node:12-alpine
 
 WORKDIR /app
 COPY ./server /app
 
 WORKDIR /app/server
 RUN yarn
 RUN yarn start

It really does work until I get to yarn start (Which I should probably run in the docker-compose as it needs to mongodb container to be running. I just don't know how to run this in the docker-compose.yml, or force the client to wait for this command to be run before running its own yarn start).

2
  • 1
    yarn start should be the CMD (what runs when you start a container) and not a RUN command (which is run when creating the image used to satrt a container later)
    – Tensibai
    Commented Apr 27, 2021 at 8:59
  • Thanks @Tensibai If you submit this as an answer I can accept it. I am a bit green with docker and docker-compose
    – Flotolk
    Commented Apr 27, 2021 at 11:10

1 Answer 1

1

yarn start should be the CMD of your docker image (I.e what is run when you start a container) and not a RUN command (which is run when creating the image used to satrt a container later)

From your exemple, something like this should be better:

 FROM node:12-alpine
 
 WORKDIR /app
 COPY ./server /app
 
 WORKDIR /app/server
 RUN yarn
 CMD yarn start

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.