<p><code>yarn start</code> should be the <code>CMD</code> of your docker image (I.e what is run when you start a container) and not a <code>RUN</code> command (which is run when creating the image used to satrt a container later)</p>
<p>From your exemple, something like this should be better:</p>
<pre><code> FROM node:12-alpine
 
 WORKDIR /app
 COPY ./server /app
 
 WORKDIR /app/server
 RUN yarn
 CMD yarn start
</code></pre>

CC BY-SA 4.0
2021-04-27T12:26:20.820Z
2021-04-27T12:26:20.820Z
Tensibai
<p>So I am trying to start up an server that has:</p>
<ul>
<li>a mongodb container</li>
<li>a backend container</li>
<li>a client container</li>
</ul>
<p>Both server containers require me to run <code>yarn start</code> at the end. However, when I run this in the dockerfile the image never stops being built as the <code>yarn start</code> command technically never stops running.</p>
<p>The client requires the backend to be up already, and the backend requires the mongodb db instance to be up.</p>
<p>How do I get this server running in docker compose?</p>
<p>Here is my backend dockerfile</p>
<pre><code> FROM node:12-alpine
 
 WORKDIR /app
 COPY ./server /app
 
 WORKDIR /app/server
 RUN yarn
 RUN yarn start
</code></pre>
<p>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 <code>docker-compose.yml</code>, or force the client to wait for this command to be run before running its own <code>yarn start</code>).</p>

CC BY-SA 4.0
2021-04-27T08:59:01.167Z
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
CC BY-SA 4.0
2021-04-27T11:10:25.187Z
Thanks @Tensibai
If you submit this as an answer I can accept it.
I am a bit green with docker and docker-compose
Flotolk
<docker><docker-compose>
yarn server with docker-compose
Flotolk
# yarn server with docker-compose

(Asked by: username_0 on 2021-04-26)

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).

**Tags:** docker, docker-compose

> **Comments:**
> **username_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)  
> **username_0**: Thanks @username_1 If you submit this as an answer I can accept it. I am a bit green with docker and docker-compose  

---

## 1 answers

### Answer by username_1 on 2021-04-27. Score: 1 | Accepted answer

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


---

