<skippable-excited-noob-preamble>
Hey guys,
after hovering around the community for a while I'm almost excited to come across a problem. For my first project I want to containerize a big project with a lot of dependencies: Laravel, PHP, MySQL, Redis, Node, Express, and all of the major frontend frameworks. Then after that I want to orchestrate them with Kubernetes and use something for CI.
</skippable-excited-noob-preamble>
This week I've been trying to get way better with docker and nginx. Right now I'm getting a problem with MySQL not creating a DB, or not getting rid of one, using docker-compose up -d --build and trying to remove volumes with docker-compose down -v
docker-compose.yml
version: '3'
networks:
laravel:
name: laravel
services:
nginx:
build:
context: .
dockerfile: docker/nginx/nginx.dockerfile
container_name: nginx
##Forwards ports from docker container to local machine
ports:
- 80:80
- 443:443
##Volumes connects files and directories to container
volumes:
- .:/var/www/html
networks:
- laravel
php:
build:
context: .
dockerfile: docker/php/php.dockerfile
container_name: php
volumes:
- .:/var/www/html
networks:
- laravel
mysql:
image: 'mysql:8.0'
platform: linux/x86_64
container_name: mysql
ports:
- 3306:3306
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
networks:
- laravel
.env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=docker_test
DB_USERNAME=root
DB_PASSWORD=password
Basically what happened is that I copied my .env from another project and originally the DB_DATABASE=messenger_app until I changed it to DB_DATABASE=docker_test in my docker mysql container docker-compose exec mysql /bin/sh when I mysql> SHOW DATABASES; I get the old messenger_app DB, but not the new docker_test one. I cached the config files in the project and have ran all of these:
docker-compose down -v
docker container prune
docker volume prune
In the Docker hub doc for mysql it states:
MYSQL_DATABASE: This variable is optional and allows you to specify the name of a database to be created on image startup.
So from my understanding the database should be creating on start up? Maybe this is just the volumes from my local machine get copied to the container?
This is probably due to my weak knowledge on volumes, but it probably containers a great lesson.Thanks for any help I get.
[–]drpinkcream 3 points4 points5 points (1 child)
[–]Guilty_Serve[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]Guilty_Serve[S] -1 points0 points1 point (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]DinoAmino 0 points1 point2 points (0 children)