Unable to run dockerized strapi app on ubuntu server with postgres db via Gitlab CI

System Information
  • Strapi Version: ?
  • Operating System: linux
  • Database: posgres
  • Node Version:
  • NPM Version:
  • Yarn Version:

PLEASE HELP! :sos:
I am trying to deploy strapi with postgres db via gitlab CI to an ubuntu server. While I manage to get strapi run both locally and remotely when I trigger deployment via Gitlab CI I am unable to get strapi up and running.

  1. I tried to use docker-compose up as I did locally and remotely but the job never gets to the point of Attaching to postgres_1, strapi_1 (taken from the log) and the app is not running

.gitlab.ci file
image: registry.xxx.nl/xxx/builder:latest

stages:
  - deploy
  
deploy-acceptance:
  stage: deploy
  environment:
    name: acceptance
  tags:
    - docker-in-docker
  variables:
    HOST: 192.168.216.00
    PORT: 1337
    DATABASE_CLIENT: postgres
    DATABASE_NAME: strapi
    DATABASE_HOST: postgres
    DATABASE_PORT: 5432
    DATABASE_USERNAME: strapi
    DATABASE_PASSWORD: $DATABASE_PASSWORD
    PGDATA: /var/lib/postgresql/data/db_data
    POSTGRES_DB: strapi
    POSTGRES_USER: strapi
    POSTGRES_PASSWORD: $DATABASE_PASSWORD
  script:
    - mkdir ~/.ssh && cp "$SSH_ACC_KEY" ~/.ssh/id_ecdsa
    - chmod 600 ~/.ssh/id_ecdsa
    - ssh-keyscan -t ecdsa 192.168.216.00 >> ~/.ssh/known_hosts
    - docker-compose -f docker-compose.yml -H "ssh://root@192.168.216.00" pull
    - COMPOSE_HTTP_TIMEOUT=1200 DOCKER_CLIENT_TIMEOUT=1200 docker-compose -f docker-compose.yml -H "ssh://root@192.168.216.00" up --remove-orphans -d
  rules:
    - if: '$CI_COMMIT_REF_NAME == "master" && $CI_PROJECT_PATH == "project-name/strapi"'
  1. I tried to use docker run with the environment variables which resulted in
    debug :no_entry: Server wasn’t able to start properly. error KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?

.gitlab-ci.yml
image: registry.xxxx.nl/xxx/builder:latest

stages:
  - deploy
  
deploy-acceptance:
  stage: deploy
  environment:
    name: acceptance
  tags:
    - docker-in-docker
  variables:
    HOST: 192.168.216.00
    PORT: 1337
    DATABASE_CLIENT: postgres
    DATABASE_NAME: strapi
    DATABASE_HOST: postgres
    DATABASE_PORT: 5432
    DATABASE_USERNAME: strapi
    DATABASE_PASSWORD: $DATABASE_PASSWORD
    PGDATA: /var/lib/postgresql/data/db_data
    POSTGRES_DB: strapi
    POSTGRES_USER: strapi
    POSTGRES_PASSWORD: $DATABASE_PASSWORD
    POSTGRES_INITDB_ARGS: "--min=0 --max=10 --idleTimeoutMillis=30000 --createTimeoutMillis=30000 --acquireTimeoutMillis=30000"
  script:
    - mkdir ~/.ssh && cp "$SSH_ACC_KEY" ~/.ssh/id_ecdsa
    - chmod 600 ~/.ssh/id_ecdsa
    - ssh-keyscan -t ecdsa 192.168.216.00 >> ~/.ssh/known_hosts
    - docker-compose -f docker-compose.yml -H "ssh://root@192.168.216.00" pull
    - COMPOSE_HTTP_TIMEOUT=1200 DOCKER_CLIENT_TIMEOUT=1200 docker run -e DATABASE_CLIENT=postgres -e DATABASE_NAME=strapi -e DATABASE_HOST=192.168.216.00 -e DATABASE_PORT=5432 -e DATABASE_USERNAME=strapi -e DATABASE_PASSWORD=$DATABASE_PASSWORD -p 1337:1337 -v `pwd`/project-name:/srv/app
      strapi/strapi
  rules:
    - if: '$CI_COMMIT_REF_NAME == "master" && $CI_PROJECT_PATH == "projectname-strapi"'

docker-compose.yml file

version: '3'
services:
  strapi:
    image: strapi/strapi
    environment:
      DATABASE_CLIENT: $DATABASE_CLIENT
      DATABASE_NAME: ${DATABASE_NAME}
      DATABASE_HOST: ${DATABASE_HOST}
      DATABASE_PORT: ${DATABASE_PORT}
      DATABASE_USERNAME: ${DATABASE_USERNAME}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD}
    volumes:
      - ./app:/srv/app
    ports:
      - '1337:1337'
    depends_on:
      - postgres

  postgres:
    image: postgres
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      PGDATA: /var/lib/postgresql/data/db_data
    volumes:
      - ~/db_data:/var/lib/postgresql/data/
volumes:
  db_data:

Have you tried to connect to DB from Ubuntu’s CLI? Have you verified that all docker images are running/ports are exposed and checked their logs?

From postgres image I see that you are not exposing it’s port, which means it is not accessible.

So you should also add:

ports:
      - 5432:5432