Answer the question
In order to leave comments, you need to log in
How to perform a migration in a Docker container?
I run the project via docker-compose up - and get: SQLSTATE[HY000] [2002] Connection refused.
At the same time, if you run php artisan migrate in the container itself in interactive mode, then everything is OK. Please help, I don't know what to do anymore. I tried everything, I want the project to rise immediately through docker compose-up, without additional dances with a tambourine.
dockerfile:
FROM php:7.3-apache
WORKDIR /var/www/html
COPY . .
# ENV DB_HOST="db"
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& apt update && apt install -y git zip unzip \
&& docker-php-ext-install pdo_mysql \
&& a2enmod rewrite \
&& composer install \
&& chmod -R 0777 storage/
ENTRYPOINT ["/var/www/html/run.sh"]
#!/bin/bash
php artisan cache:clear
php artisan config:clear
php artisan migrate
version: "3.9"
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: 1111
MYSQL_DATABASE: parser
MYSQL_USER: user
MYSQL_PASSWORD: password
networks:
- parser_docker_network
server:
depends_on:
- db
environment:
DB_HOST: db
build: .
ports:
- "8100:80"
restart: always
volumes:
- ./conf/vhost.conf:/etc/apache2/sites-enabled/000-default.conf
- ./conf/hosts:/etc/hosts
networks:
- parser_docker_network
networks:
parser_docker_network:
Answer the question
In order to leave comments, you need to log in
Hi,
1. most likely your env vars in docker compose are wrong, they should be in server section, not db section or both
2. try in run.sh instead of php artisan migrate, write sleep 1800
go inside working php container with docker exec -ti container_id bash and execute env there - see if there are variables for php script to work
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question