Hi everyone,
Maybe I’m going to ask an obious question, but I’m going to drop it anyway
One of the problems I’m facing is that I cannot connect to my MySQL app.
I checked this post: Fail to run MySQL app from Dockerfile and it seems that I can run the MySQL app
but not connect to it on my Laravel application (also running in Fly.io).
When looking into the article I notices that there was a mount set but never used in the docker container (Am I right? and how can I do this for MySQL)
My Dockerfile is something like this:
FROM mysql:5.7.38
RUN chown -R mysql:root /var/lib/mysql/
ENV MYSQL_ALLOW_EMPTY_PASSWORD true
ARG MYSQL_DATABASE=database
ARG MYSQL_USER=root
ARG MYSQL_PASSWORD=root122211
ARG MYSQL_ROOT_PASSWORD=root122211
ENV MYSQL_DATABASE=${MYSQL_DATABASE}
ENV MYSQL_USER=${MYSQL_USER}
ENV MYSQL_PASSWORD=${MYSQL_PASSWORD}
ENV MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
EXPOSE 3306
CMD ["mysqld"]
The secrets are set
Dockerfile from laravel application
# syntax = docker/dockerfile:experimental
FROM alpine:edge as base
LABEL fly_launch_runtime="laravel"
RUN apk update \
&& apk add curl zip unzip tzdata supervisor nginx htop vim ca-certificates rsync \
php8 php8-cli php8-pecl-mcrypt \
php8-soap php8-openssl php8-gmp \
php8-pdo_odbc php8-json php8-dom \
php8-pdo php8-zip php8-pdo_mysql \
php8-sqlite3 php8-pdo_pgsql php8-bcmath \
php8-gd php8-odbc php8-pdo_sqlite \
php8-gettext php8-xmlreader php8-bz2 \
php8-iconv php8-pdo_dblib php8-curl \
php8-ctype php8-phar php8-xml \
php8-common php8-mbstring php8-tokenizer \
php8-xmlwriter php8-fileinfo php8-opcache \
php8-simplexml php8-pecl-redis php8-sockets \
php8-pcntl php8-posix php8-pecl-swoole \
php8-fpm \
&& cp /etc/nginx/nginx.conf /etc/nginx/nginx.old.conf \
&& rm -rf /etc/nginx/http.d/default.conf \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& adduser -D -u 1000 -g 'app' app \
&& addgroup nginx app \
&& mkdir -p /var/run/php \
&& chown -R app:app /var/run/php \
&& mkdir -p /var/www/html
WORKDIR /var/www/html
# copy application code, skipping files based on .dockerignore
COPY . /var/www/html
# Install dependencies, configure server
# For the time being, we run "composer update" as best effort to get php 8.0 working
RUN composer update \
&& composer install --optimize-autoloader --no-dev \
&& mkdir -p storage/logs \
&& chown -R app:app /var/www/html \
&& /usr/bin/crontab docker/crontab \
&& mv docker/supervisor.conf /etc/supervisord.conf \
&& mv docker/nginx.conf /etc/nginx/nginx.conf \
&& mv docker/server.conf /etc/nginx/server.conf \
&& mv docker/php.ini /etc/php8/conf.d/php.ini \
&& sed -i 's/protected \$proxies/protected \$proxies = "*"/g' app/Http/Middleware/TrustProxies.php
# If we're not using Octane, configure php-fpm
RUN if ! grep -Fq "laravel/octane" /var/www/html/composer.json; then \
rm -rf /etc/php8/php-fpm.conf; \
rm -rf /etc/php8/php-fpm.d/www.conf; \
mv docker/php-fpm.conf /etc/php8/php-fpm.conf; \
mv docker/app.conf /etc/php8/php-fpm.d/app.conf; \
elif grep -Fq "spiral/roadrunner" /var/www/html/composer.json; then \
if [ -f ./vendor/bin/rr ]; then ./vendor/bin/rr get-binary; fi; \
rm -f .rr.yaml; \
fi
# clear Laravel cache that may be left over
RUN composer dump-autoload \
&& php artisan optimize:clear \
&& chmod -R ug+w /var/www/html/storage \
&& chmod -R 755 /var/www/html \
&& php artisan migrate:fresh --force
# Multi-stage build: Build static assets
FROM node:14 as node_modules_go_brrr
RUN mkdir /app
RUN mkdir -p /app
WORKDIR /app
COPY . .
RUN if [ -f "yarn.lock" ]; then \
yarn install; \
elif [ -f "package-lock.json" ]; then \
npm ci --no-audit; \
else \
npm install; \
fi
# Create final container, adding in static assets
FROM base
COPY --from=node_modules_go_brrr /app/public /var/www/html/public-npm
RUN rsync -ar /var/www/html/public-npm/ /var/www/html/public/ \
&& rm -rf /var/www/html/public-npm
# The same port nginx.conf is set to listen on and fly.toml references (standard is 8080)
EXPOSE 8080
ENTRYPOINT ["/var/www/html/docker/run.sh"]
The migration is breaking:
#13 8.226 In Connection.php line 759:
#13 8.226
#13 8.226 SQLSTATE[HY000] [2002] Connection refused (SQL: SHOW FULL TABLES WHERE tabl
#13 8.226 e_type = 'BASE TABLE')
#13 8.226
#13 8.226
#13 8.226 In Connector.php line 70:
#13 8.226
#13 8.226 SQLSTATE[HY000] [2002] Connection refused
#13 8.226
#13 8.226
I can ping and ssh into the other server (
fly ssh console
)
It seems that the password is not set correctly? I think