Reputation: 4808
I'm beginner with Docker and I'm watching tutorial Docker for PHP Developers by Paul Redmond. But when he is creating MySQL database everything is working fine but I have problem and cannot find out where is.
I'm using Laravel and I need to connect to the database. But it seems that MySQL container not create a new user and I don't have any idea why.
Dockerfile:
FROM php:7.3.1-apache-stretch
COPY . /var/www/html
COPY docker/vhost.conf /etc/apache2/sites-available/000-default.conf
RUN chown -R www-data:www-data /var/www/html \
&& docker-php-ext-install pdo_mysql \
&& a2enmod rewrite
docker-compose.yml:
version: "3"
services:
app:
image: laravel-www
container_name: laravel-www
build:
context: .
dockerfile: docker/Dockerfile
ports:
- 8080:80
mysql:
container_name: laravel-mysql
image: mysql:5.7
environment:
MYSQL_DATABASE: homestead
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: homestead
MYSQL_SECRET: secret
ports:
- 3306:3306
.env in Laravel:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
After login into mysql container and into mysql I tried to show all users but there is no "homestead" user who should be created when container is initialized.
docker-compose exec mysql bash
root@8ad8531fb0e0:/# mysql -u root --host=127.0.0.1 -proot
mysql> select User from mysql.user;
+---------------+
| User |
+---------------+
| root |
| mysql.session |
| mysql.sys |
| root |
+---------------+
I already tried to remove all containers and build it again. I'm not doing anything fancy so what I'm doing wrong?
Upvotes: 1
Views: 2039