I'm very new to Docker and stepped into my first real project with it. We have a php app using Codeigniter and PostgreSQL and it works great. Now I'm trying to dockerize it and I've run into some troubles with the pdo_pgsql driver.
I found some help online to get the pdo_pgsql driver to install, however it was all out of date solutions for php-5x. What I have seemed to work because I checked the phpinfo page and my php.ini was loaded in correctly and says the pdo_pgsql and pgsql drivers are both installed and active????
Here is the error:
Strange thing is when I first hit the page I only get the first error. Then if I refresh the page the second error shows up.
When I log into the container and cd
to the directory where it says the file does not exist, I can clearly see pdo.so
,pdo_pgsql.so
, and pgsql.so
.
An Error Was Encountered
You have specified an invalid database connection group (dockerize) in your config/database.php file.
A PHP Error was encountered
Severity: Core Warning
Message: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20160303/pgsql' - /usr/local/lib/php/extensions/no-debug-non-zts-20160303/pgsql: cannot open shared object file: No such file or directory
Filename: Unknown
Here is the Dockerfile
:
# Dockerfile
FROM php:7.1.12-apache
MAINTAINER Me <[email protected]>
COPY deploy/config/php.ini /usr/local/etc/php/
COPY target/myapp.tar.gz /var/www/html
RUN apt-get update
# Install Postgre PDO
RUN apt-get install -y libpq-dev \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo pdo_pgsql pgsql
RUN tar -xzf /var/www/html/myapp.tar.gz \
&& cd /var/www/html \
&& rm -f myapp.tar.gz \
&& OLD_URL='http://localhost:8080' \
&& NEW_URL='http://dockerhost:8080' \
&& sed -i -e "s#$OLD_URL#$NEW_URL#" "/var/www/html/application/config/config.php"
EXPOSE 80
EXPOSE 443
Here is my docker-compose.yml
:
version: "3"
services:
app:
image: me/myapp:v1
build: .
ports:
- "8080:80"
- "8043:443"
postgres:
image: postgres:9.6.6
ports:
- "5432:5432"
Here is my Codeigniter database.php
:
This tries to connect to the Postgres in another container supposedly provided by the docker-compose with the above yml. I read a few places that said I simply use postgres
as the host for the connection because the docker-compose.yml
file has a service named postgres
. This sounds kinda fishy to me, does this look right?
$active_group = "dockerize";
$query_builder = TRUE;
$db['dockerize'] = array(
'dsn' => 'pgsql:host=postgres;port=5432;dbname=mydb;user=postgres;password=postgres',
'hostname' => 'postgres',
'username' => 'postgres',
'password' => 'postgres',
'database' => 'mydb',
'dbdriver' => 'pdo',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
fyi: all the above is anonymized and slimmed down for readability