Score:0

How do I run Laravel App with mysql using only Dockerfile?

us flag

I want to be able to enable my visitors to upload their laravel app to my server, and I want to run each app in a docker container. And I also want them to be able to have database access. My current Dockerfile is as such, but when I run docker exec -i myContainer echo "create database laravel3" | mysql, and then docker exec -i test30f php artisan migrate, I get an error Connection refused.

My Dockerfile is:

FROM mysql:5.7
ENV MYSQL_ALLOW_EMPTY_PASSWORD true
EXPOSE 3306
CMD ["mysqld"]

FROM php:7.4-fpm-alpine

RUN docker-php-ext-install pdo pdo_mysql sockets
RUN curl -sS https://getcomposer.org/installer<200b> | php -- \
     --install-dir=/usr/local/bin --filename=composer

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

WORKDIR /app
COPY . /app
RUN composer install
RUN cp .env.example .env && php artisan key:generate
CMD php artisan serve --host=0.0.0.0 --port=8000
EXPOSE 8000

My .env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel3
DB_USERNAME=root
DB_PASSWORD=
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.