@ivan2nn can you try changing DB_HOST from postgresql to localhost instead?
Docker Laravel+Postgresql translation to hostname
I am approaching for the first time the Docker universe.
I have this 3 years old working Laravel App (5.2), connected to a Psotgresql db.
The asked some modifications and to bring it to an internal server of their own.
I cannot adapt it to a new Laravel version yet, so I thought it would have been a good idea to deploy in container the 5.2 app in case other people need to work on it.
So far, following some instructions, I ge to this point:
docker-compose.yml:
version: '3'
networks:
laravel:
driver: bridge
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8080:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- psql
networks:
- laravel
psql:
image: postgres:12.7-alpine
container_name: postgresql
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
- POSTGRES_USER=xxxx
- POSTGRES_PASSWORD=yyyy
- POSTGRES_DB=zcreport_ecostarfinal_new
restart: always
tty: true
ports:
- "5433:5432"
volumes:
- './postgresql:/var/lib/postgresql/data'
networks:
- laravel
php:
build:
context: ./php
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
networks:
- laravel
I have the /postgresql folder with (I hope) the data I copied from my local /var/lib/postgresql/12/main folder I have the /src folder whre i put my laravel app
And this is the .env inside /src folder:
DB_CONNECTION=pgsql
DB_HOST=postgresql
DB_PORT=5432
DB_DATABASE=zcreport_ecostarfinal_new
DB_USERNAME=xxxx
DB_PASSWORD=yyyy
Now, when I build and run the docker-compose and check the localhost the site loads but I get a 500 error:
PDOException in Connector.php line 55: SQLSTATE[08006] [7] could not translate host name "psql" to address: Temporary failure in name resolution
I don't know how to solve this problem
Thanks
I see @ivan2nn although from what I understand volumes don't work that way.
What you could do is delete everything inside ./postgresql folder and after booting up the PostgreSQL then you manually import those data via "docker exec" (you can google it). In that way you correctly import the data not just manually copying folders.
Please or to participate in this conversation.