DEV Community

Marcelo Silva Arão
Marcelo Silva Arão

Posted on

Access the Postgres database through Docker, through a PHP API and another C#.

I have an API in PHP. I want to learn C# and I want my Application, new to C#, to access my database, which is currently accessed via the PHP API, and I want to do the same access using a C# API. I want to continue accessing through both APIs. I am unable to access my database, Postgres, which is running in a docker cotainer. Can you help me?
My current settings are:

######## docker-compose.yml

version: "3"
services:
proxy:
build:
dockerfile: docker/dev/Dockerfile-proxy
context: .
ports:
- 8080:80
links:
- php-fpm

php-fpm:
build:
dockerfile: ./docker/dev/Dockerfile
context: .
expose:
- 9000
volumes:
- ./:/src
environment:
- APP_ENV=production
- APP_TIMEZONE=UTC
- APP_DEBUG=true
- DB_CONNECTION=pgsql
- DB_HOST=db-database.com
- DB_PORT=5432
- DB_DATABASE=homolog
- DB_USERNAME=user
- DB_PASSWORD=********
- JWT_SECRET=7CCEFE3E6D4A8B37F464C4094415E950946D1
- EDUZZ_UPLOADER_API_TOKEN=3fe0e403f588db5d1d734c7
- EDUZZ_UPLOADER_API_URL=https://upload.site.com
- EDUZZ_CDN_URL=https://cdn.site.com

- ACCOUNTS_PARTNER=45463099-c60c-440b-b036
- ACCOUNTS_SECRET=3c029bb996f2e77b54f5c020

- ACCOUNTS_URL=https://accounts-api.eduzz.com

######## Dockerfile

FROM php:7.4-fpm

RUN set -x \
&& apt-get update \
&& apt-get install -y zip unzip git openssh-client libpq-dev cron

RUN set -x \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo pdo_pgsql pgsql

RUN set -x \
&& curl -L https://getcomposer.org/download/1.10.0/composer.phar -o /usr/local/bin/composer \
&& chmod +x /usr/local/bin/composer

RUN composer global require hirak/prestissimo

RUN set -x \
&& mkdir -m 777 /tmp/storage \
&& mkdir -m 777 /tmp/storage/logs \
&& mkdir -m 777 /tmp/storage/framework \
&& mkdir -m 777 /tmp/storage/framework/cache \
&& mkdir -m 777 /tmp/storage/framework/sessions \
&& mkdir -m 777 /tmp/storage/framework/views

WORKDIR /src

COPY docker/dev/php.ini /usr/local/etc/php/conf.d/php.ini
COPY docker/dev/fpm.conf /usr/local/etc/php-fpm.d/www.conf

COPY cron-file /etc/cron.d/cron-file

RUN chmod 0644 /etc/cron.d/cron-file

RUN crontab /etc/cron.d/cron-file

RUN touch /var/log/cron.log

COPY .env.prod /etc/environment

CMD cron cron-file && php-fpm

######## Operational system

OS: Ubuntu 23.10 x86_64
Kernel: 6.5.0-28-generic
CPU: Intel i3-6006U (4) @ 2.000GHz
GPU: Intel Skylake GT2 [HD Graphics 520]
Memory: 5442MiB / 15862MiB

Top comments (0)