Im trying to create docker LAMP stack image and running into a few issues with the DB connectivity. I can hit static pages on the localhost after running the container which tells me the actual image is fine but I can't figure out why the db isn't connecting. I'm using a aws db and it runs fine on my local lamp environment. Having issues with the contianer image though.
Dockerfile
# Build ui code
FROM node:8.11.4 AS npm-build
COPY code/ui /tmp/code/ui
WORKDIR /tmp/code/ui
RUN npm install bower
RUN npm install && npm run build
# Build api code
FROM sunfoxcz/php-build:5.6 AS php-build
COPY code/api /tmp/code/api
WORKDIR /tmp/code/api
RUN composer install && composer dump-autoload -o
# Build production container
FROM amazonlinux:1
# Update repo data
RUN yum makecache fast
# Install OS updates
RUN yum update -y \
&& yum-config-manager --enable epel
# Install Apache (2.4) and PHP (5.6)
RUN yum install -y httpd24 mod24_ssl php56 php56-mysqlnd php56-pgsql php-curl php56-mbstring php56-gd php56-devel php56-mcrypt php56-opcache
# Install needed packages
RUN yum install -y redis poppler-utils
# Install needed dev tools
RUN yum install -y gcc wget
# Install PHP Redis extension
RUN cd /tmp && \
wget -O phpredis-4.3.0.tar.gz https://github.com/phpredis/phpredis/archive/4.3.0.tar.gz && \
tar xvfz phpredis-4.3.0.tar.gz && \
cd phpredis-4.3.0 && \
phpize && \
./configure && \
make && \
make install && \
rm -rf /tmp/phpredis-4.3.0*
# Install needed binaries
COPY bin/pdftotext /opt/ds/bin/pdftotext
RUN chmod +x /opt/ds/bin/pdftotext
# Finally add our code files to the production container
COPY --from=php-build /tmp/code/api /var/www/html
COPY --from=npm-build /tmp/code/ui/dist /var/www/html/ui
COPY environment /etc/environment
EXPOSE 80
EXPOSE 3306
ENTRYPOINT ["httpd","-DFOREGROUND"]
environment
export DS_ENVIRONMENT="local"
export DS_DB_HOST="my-remote-host"
export DS_DB_HOST_REPLICA=""
export DS_DB_HOST_REPLICA_TWO=""
export DS_DB_NAME="my_db_name"
export DS_DB_USER="db_user"
export DS_DB_PASS="xxxxxxx"
When I run this container I get the following error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /var/www/html/vendor/illuminate/database/Connectors/Connector.php:68 Stack trace: #0 /var/www/html/vendor/illuminate/database/Connectors/Connector.php(68): PDO->__construct('mysql:host=loca...', 'root', 'root', Array) #1 /var/www/html/vendor/illuminate/database/Connectors/Connector.php(45): Illuminate\Database\Connectors\Connector->createPdoConnection('mysql:host=loca...', 'root', 'root', Array) #2 /var/www/html/vendor/illuminate/database/Connectors/MySqlConnector.php(24): Illuminate\Database\Connectors\Connector->createConnection('mysql:host=loca...', Array, Array) #3 /var/www/html/vendor/illuminate/database/Connectors/ConnectionFactory.php(183): Illuminate\Database\Connectors\MySqlConnector->connect(Array) #4 [internal function]: Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors{closure}() #5 /var/www/html/vendor/illuminate/database/Connection.php(883): call_user_func(Object(C in /var/www/html/vendor/illuminate/database/Connectors/Connector.php on line 68
I can't seem to identify where this is coming from. Obviously looks like a db connectivity isuees but 1) I don't see why it's using a localhost connection string as seen in the image. Is that the default?