Postgresql container external openproject

Hi everyone,

I’m a neophyte on the subject but I’m writing you what I’ve tried to do so far and I haven’t succeeded;

I installed open project with docker-compose.yml; the compose file automatically installs postgresql as container so it does an all in one installation;

I want to create a postgresql container database external to the open project container; I tried many but the closest to the solution was to edit the docker-compose.yml open project before running it, by changing the variable DATABASE_URL=postgres://openproject:password@openproject-db:5432/openproject which points to the postgresql container;

The problem is that the docker file recreates another postgresql container instance in addition to the one I created separately;

The original docker compose that openproject downloads is this:

“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”

version: "3.7"

networks:
 frontend:
 backend:

volumes:
 pgdata:
 opdata:

x-op-restart-policy: &restart_policy
 restart: unless-stopped
x-op-image: &image
 image: openproject/community:${TAG:-12}
x-op-app: &app
 <<: [*image, *restart_policy]
 environment:
   OPENPROJECT_HTTPS: "${OPENPROJECT_HTTPS:-true}"
   OPENPROJECT_HOST__NAME: "${OPENPROJECT_HOST__NAME:-localhost:8080}"
   OPENPROJECT_HSTS: "${OPENPROJECT_HSTS:-true}"
   RAILS_CACHE_STORE: "memcache"
   OPENPROJECT_CACHE__MEMCACHE__SERVER: "cache:11211"
   OPENPROJECT_RAILS__RELATIVE__URL__ROOT: "${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}"
   DATABASE_URL: "${DATABASE_URL:-postgres://postgres:p4ssw0rd@db/openproject?pool=20&encoding=unicode&reconnect=true}"
   RAILS_MIN_THREADS: ${RAILS_MIN_THREADS:-4}
   RAILS_MAX_THREADS: ${RAILS_MAX_THREADS:-16}
   # set to true to enable the email receiving feature. See ./docker/cron for more options
   IMAP_ENABLED: "${IMAP_ENABLED:-false}"
 volumes:
   - "${OPDATA:-opdata}:/var/openproject/assets"

services:
 db:
   image: postgres:13
   <<: *restart_policy
   stop_grace_period: "3s"
   volumes:
     - "${PGDATA:-pgdata}:/var/lib/postgresql/data"
   environment:
     POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-p4ssw0rd}
     POSTGRES_DB: openproject
   networks:
     - backend

 cache:
   image: memcached
   <<: *restart_policy
   networks:
     - backend

 proxy:
   <<: [*image, *restart_policy]
   command: "./docker/prod/proxy"
   ports:
     - "${PORT:-8080}:80"
   environment:
     APP_HOST: web
     OPENPROJECT_RAILS__RELATIVE__URL__ROOT: "${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}"
   depends_on:
     - web
   networks:
     - frontend

 web:
   <<: *app
   command: "./docker/prod/web"
   networks:
     - frontend
     - backend
   depends_on:
     - db
     - cache
     - seeder
   labels:
     - autoheal=true
   healthcheck:
     test: ["CMD", "curl", "-f", "http://localhost:8080${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}/health_checks/default"]
     interval: 10s
     timeout: 3s
     retries: 3
     start_period: 30s

 autoheal:
   image: willfarrell/autoheal:1.2.0
   volumes:
     - "/var/run/docker.sock:/var/run/docker.sock"
   environment:
     AUTOHEAL_CONTAINER_LABEL: autoheal
     AUTOHEAL_START_PERIOD: 600
     AUTOHEAL_INTERVAL: 30

 worker:
   <<: *app
   command: "./docker/prod/worker"
   networks:
     - backend
   depends_on:
     - db
     - cache
     - seeder

 cron:
   <<: *app
   command: "./docker/prod/cron"
   networks:
     - backend
   depends_on:
     - db
     - cache
     - seeder

 seeder:
   <<: *app
   command: "./docker/prod/seeder"
   restart: on-failure
   networks:
     - backend

“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”

I home for some help

You actually create and run containers, you don’t actually install anything.

I assume openproject-db is a typo, as the service is named db and there is no alias declared in the network section of the service. Though, you do use it correct in the environment variables.

Did you know that you can use docker compose config to render the compose file where all yaml-anchors are already resolved?

As long as you use the same project name (either provided as -p {project name}, if not provided the folder name where the compose file is located will be used), the container for the db service will always be named {projectname}_db_1. Thus, it doesn’t appear to be possible that a second container is created. Unless of course, the shared compose file is not the one you actually use.

Please share the output of docker container inspect {container id or name} --format '{{json .Config.Labels}}' |jq for the two postgres instances.

Note: setting the grace period to such a short time span for the postgres container can lead to corrupt data, as it literary kills the container when it doesn’t stop within 3 second after it received the stop event. People usually raise the grace period to make sure data remains consistent, and not shorten it.

Update: it can be that the generated container name uses dashes instead of underscores. I see both being used. On docker-ce I see underscores being used, on Docker Desktop I see dashes instead.

I recreated the open project containers again;

changing the variable DATABASE_URL=postgres://openproject:password@openproject-db:5432/openproject which points to the postgresql container;

Yes this is an example; so in section network I have to put same service name after @;

Please share the output of docker container inspect {container id or name} --format '{{json .Config.Labels}}' |jq for the two postgres instances.
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”

“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”"

Container created for docker-compose open project:

“”“”“”“”“”“”“”“”"

 "com.docker.compose.config-hash": "842c60c7e0e901f4304a95e25290852a56a0b5bf35839573c864dbcdf5aa9807",
  "com.docker.compose.container-number": "1",
  "com.docker.compose.oneoff": "False",
  "com.docker.compose.project": "compose",
  "com.docker.compose.project.config_files": "docker-compose.yml",
  "com.docker.compose.project.working_dir": "/home/maselli/openproject/compose",
  "com.docker.compose.service": "db",
  "com.docker.compose.version": "1.29.2"

“”“”“”“”“”
Container created for docker-compose for postgresql:

“”“”“”“”“”“”“”“”“”

"com.docker.compose.config-hash": "8886c174ccc42e2650116a38a80ba765acdfde0b980bf19a21f04629c2806278",
  "com.docker.compose.container-number": "1",
  "com.docker.compose.oneoff": "False",
  "com.docker.compose.project": "maselli",
  "com.docker.compose.project.config_files": "docker-compose.yml",
  "com.docker.compose.project.working_dir": "/home/maselli",
  "com.docker.compose.service": "database",
  "com.docker.compose.version": "1.29.2"

“”“”“”“”“”“”“”“”“”“”“”

Thanks for the reply; I repeat, I’m not an expert, I just want a simple configuration from openproject that points to the external postgres container and not the postgres created by open project

Both deployments use a different project name (value of com.docker.compose.project), and both use the default name from the last part of the path where the compose file is located (which, like I already wrote, is the default behavior if the project name is not provided)

So, yes, you created two completely different compose deployments. So having everything twice is to be expected.

I missed out on that part of your last response.

I just re-checked your first post, seems like the used wording did put me on the wrong track. In your compose file the postgres container is already separated than the open project container. So it was not obvious that you meant a database container outside/external to the compose project. Well, now it is.

There are two ways to achieve this:

  1. use the host name of your docker host and the published port for the container to access the database
  2. put database and consumer container in the same container network. This allows to connect to the database using the service name thanks to dns-based service discovery, even though the containers are not in the same compose project.

Which one of those ways are you trying to use? If it’s the second: please share both compose files.

“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a6d252d7c116 openproject/community:12 “./docker/prod/entry…” 3 hours ago Up 3 hours 5432/tcp, 0.0.0.0:8080->80/tcp, :::8080->80/tcp compose_proxy_1
d52be303fe2d openproject/community:12 “./docker/prod/entry…” 3 hours ago Up 3 hours (healthy) 80/tcp, 5432/tcp compose_web_1
066257c971e9 openproject/community:12 “./docker/prod/entry…” 3 hours ago Up 3 hours 80/tcp, 5432/tcp compose_worker_1
d2181d835794 openproject/community:12 “./docker/prod/entry…” 3 hours ago Up 3 hours 80/tcp, 5432/tcp compose_cron_1
27d9b8f4247d postgres:13 “docker-entrypoint.s…” 3 hours ago Up 3 hours 5432/tcp compose_db_1
46368583b924 memcached “docker-entrypoint.s…” 3 hours ago Up 3 hours 11211/tcp compose_cache_1
bb6ef5133dab openproject/community:12 “./docker/prod/entry…” 3 hours ago Exited (0) 3 hours ago compose_seeder_1
8662649574f2 willfarrell/autoheal:1.2.0 “/docker-entrypoint …” 3 hours ago Up 3 hours (healthy) compose_autoheal_1
7720c726d139 postgres “docker-entrypoint.s…” 6 hours ago Exited (0) 6 hours ago postgres_container

“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”"

The container 7720c726d139 is container created with docker-compose dedicated to build postgresql only;

All other containers were created by docker-compose pull for open project and it created me All in one all these containers in one including the postgresql one;

I would like to understand if there is a way to make the open project container use the database container 7720c726d139 external, instead of the container 27d9b8f4247d that is internal to open project;

In other words, I would like to 1) create an open project with docker compose without installing postgresql and then link it to the external postegresql container or
2) create a docker compose open project which already points to the external container

or alternatively something I haven’t said so far
3) leave open All in one project + all integrated postgresql and create a connection that allows me to access the postgresql db container from the outside from the internet remotely.

Is this last solution point 3 possible if the other 2 previous ones are not possible?

Please wrap you log output and commands in a “Preformatted text” block. It did change it on your previous posts. Please click on the edit button on one of your posts where I corrected it and look what I did, and apply the same formatting to your new posts.