Docker Community Forums

Share and learn in the Docker community.

Docker compose starts app container in restarting loop


(Perpetualwar) #1

When I start image without compose just by docker run -dit , it works nicely and I can exec into it.

However if I try to use docker-compose -f docker-compose.yml up -d, its stuck in constant restarting loop. Logs show nothing.

Important that in yml file I have postgres as a dependable service to app service. Postres container is up normally, but app container is stuck.

Also tried with docker stack with same yml file, same thing happens.

Below is my test yml file.

Help is appreciated.

version: '3.3'

      - db
      - '449:443'
    restart: always
      APP_DB_HOST: db:5432
      APP_DB_USERNAME: rragequit
      APP_DB_PASSWORD: uyIYGi&679bgUJ

    image: postgres:10
    restart: always
      - '5433:5432'
      DB_USERNAME: rragequit
      DB_DATABASE: rragequit
      DB_PASSWORD: uyIYGi&679bgUJ

(Caldarolad) #2

We’d have to see your Dockerfile and run command to confirm, but my suspicion is that your CMD/ENTRYPOINT is a single command that runs, and then finishes. Once it finishes, the container stops. Since you have restart: always, it starts back up, runs the command, and stops again.

Try using a docker run command without the -it You should see the same results.

You’ll likely need to change your CMD/ENTRYPOINT to something that stays up.

(Perpetualwar) #3

FROM node:10

RUN mkdir rragequit

WORKDIR /rragequit

COPY . ./rragequit

RUN yarn install

# RUN yarn migrate:run

# RUN yarn seed:run

# RUN yarn start


# CMD []

As you can see there is several problems with my dockerfile. I don’t use any CMD , also problem with RUN yarn install as it says no network connection and I need to run migrate and seed afterwards… but the problem is how can I run migrate and seed when I dont have postgres container running.

I suppose those stuff should be done in compose yml file.

But all of that should happen before I start my app. So what do you recommend for me to make this work, both dockerfile and compose.yml wise ?

Im pretty noobish with this.

Thanks for your help.

(Caldarolad) #4

When you manually use the docker run -dit command, you’ll need to document every single command you run in order to install all the necessary apps and bring them up. Put all of those commands into the Dockerfile. At this point I would recommend going through more documentation and tutorials.

(Perpetualwar) #5

I appreciate the answer, but could you be more specific about how can I run migration inside dockerfile, when I need to run postgres container first (which will happen with compose up) ?