Hello everyone, I’m new to docker and I have some trouble in my Mysql volume.
It always restart and delete my volume everyday.
Here is my docker-compose
services:
app:
build:
context: .
dockerfile: Dockerfile
image: laravel-app
container_name: laravel-app
restart: unless-stopped
working_dir: /var/www
volumes:
- .:/var/www
depends_on:
- mysql
networks:
- app-network
mysql:
image: mysql:8.0
container_name: mysql
restart: unless-stopped
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: root
volumes:
- mysql-data:/var/lib/mysql
networks:
- app-network
nginx:
image: nginx:latest
container_name: nginx
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- .:/var/www
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- /etc/letsencrypt:/etc/letsencrypt:ro
- ./certbot:/var/www/certbot
depends_on:
- app
networks:
- app-network
certbot:
image: certbot/certbot
container_name: certbot
volumes:
- /etc/letsencrypt:/etc/letsencrypt
- ./certbot:/var/www/certbot
profiles:
- manual
networks:
- app-network
artisan:
build:
context: .
dockerfile: Dockerfile
entrypoint: ["php", "artisan"]
volumes:
- .:/var/www
depends_on:
- mysql
networks:
- app-network
volumes:
mysql-data:
name: mysql-data
networks:
app-network:
driver: bridge
here is my docker ps
➜ dailyreport git:(main) docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c73b6212914a nginx:latest "/docker-entrypoint.…" 23 hours ago Up 23 hours 0.0.0.0:80->80/tcp, [::]:80->80/tcp, 0.0.0.0:443->443/tcp, [::]:443->443/tcp nginx
94c6c17d174a laravel-app "docker-php-entrypoi…" 23 hours ago Up 23 hours 9000/tcp laravel-app
c5751ee14960 mysql:8.0 "docker-entrypoint.s…" 23 hours ago Up 15 hours 0.0.0.0:3306->3306/tcp, [::]:3306->3306/tcp, 33060/tcp mysql
and here is the logs
2025-07-21T16:24:16.615175Z 29 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.42).
2025-07-21T16:24:18.036574Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.42) MySQL Community Server - GPL.
2025-07-21 16:24:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.42-1.el9 started.
2025-07-21 16:24:18+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2025-07-21 16:24:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.42-1.el9 started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2025-07-21T16:24:19.180786Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2025-07-21T16:24:19.182251Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.42) starting as process 1
2025-07-21T16:24:19.187638Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-07-21T16:24:19.353205Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-07-21T16:24:19.537413Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2025-07-21T16:24:19.537447Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2025-07-21T16:24:19.539981Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2025-07-21T16:24:19.568097Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2025-07-21T16:24:19.568206Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.42' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
2025-07-21T18:32:55.878452Z 27 [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'
I use Makefile to install it
DOCKER_COMPOSE_FILE = docker-compose.yml
COMPOSE_PROJECT_NAME = laravel_project
DOCKER_COMPOSE = docker compose -p $(COMPOSE_PROJECT_NAME) -f $(DOCKER_COMPOSE_FILE)
DOCKER_COMPOSE_EXEC = $(DOCKER_COMPOSE) exec -T
EXEC_APP = $(DOCKER_COMPOSE_EXEC) app
install:
@echo ">> stop all containers..."
$(DOCKER_COMPOSE) stop
$(DOCKER_COMPOSE) rm -f
@echo ">> Building project..."
$(DOCKER_COMPOSE) build
$(DOCKER_COMPOSE) up -d
@echo ">> Installing dependencies..."
$(EXEC_APP) composer install
@echo "✅ Installation complete"
start:
$(DOCKER_COMPOSE) stop
$(DOCKER_COMPOSE) up -d
@echo "✅ Containers started and running on http://localhost:8080"
stop:
$(DOCKER_COMPOSE) stop
@echo "✅ All containers stopped"
check:
$(EXEC_APP) composer install
$(EXEC_APP) ./vendor/bin/phpstan analyse
$(EXEC_APP) ./vendor/bin/php-cs-fixer fix --dry-run --diff
shell:
$(DOCKER_COMPOSE) exec app bash
mysql-shell:
docker exec -it mysql bash
clean:
$(DOCKER_COMPOSE) down -v --remove-orphans
migrate:
$(EXEC_APP) php artisan migrate:fresh --seed
.PHONY: install start check bash clean migrate
Someone can help me to resolve this issue.
It’s host on OVH vps cloud
thank you