PHP:
<?php
$dbconn = pg_connect("host=web-containers_postgres_1 port=5432 dbname=messenger user=admin password=root")
or die('Could not connect: ' . pg_last_error());
// Performing SQL query
$query = 'SELECT * FROM test';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
// Printing results in HTML
echo "<table>\n";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
// Free resultset
pg_free_result($result);
// Closing connection
pg_close($dbconn);
?>
docker-compose:
version: '3'
services:
nginx-front:
image: nginx:1.17.8
volumes:
- ./code-front:/code
- ./docker/nginx-front.conf:/etc/nginx/conf.d/nginx-front.conf
networks:
net:
ipv4_address: 192.168.240.2
nginx-back:
image: nginx:1.17.8
volumes:
- ./public:/code-back
- ./code-back:/code
- ./docker/nginx-back.conf:/etc/nginx/conf.d/nginx-back.conf
networks:
net:
ipv4_address: 192.168.240.3
php-back:
image: php:8-fpm
volumes:
- ./code-back:/code
networks:
net:
ipv4_address: 192.168.240.4
build:
context: .
dockerfile: Dockerfile
depends_on:
- postgres
postgres:
image: postgres:13.3
environment:
POSTGRES_DB: "messenger"
POSTGRES_USER: "admin"
POSTGRES_PASSWORD: "root"
volumes:
- ../2. Init Database:/docker-entrypoint-initdb.d
- ./messenger:/var/lib/postgresql/data
ports:
- 5432:5432
networks:
net:
driver: bridge
ipam:
config:
- subnet: 192.168.240.0/24
app-network:
driver: bridge
my_test_app:
driver: bridge
Dockerfile:
FROM php:8-fpm
RUN apt-get update && \
apt-get install -y libpq-dev && \
docker-php-ext-install pdo pdo_pgsql pgsql
Список запущенных контейнеров:
Как исправить?