fbraz3 / lemp-docker

Apache License 2.0
14 stars 6 forks source link

how to mount the nginx/php log and the MySQL database #5

Closed xu4wang closed 7 months ago

xu4wang commented 7 months ago

I create a docker compose file

version: '3.8'  
services:
  web:
    image: fbraz3/lnmp
    volumes:
      - ./:/app/public/
    ports:
      - "127.0.0.1:8081:80"
      - "127.0.0.1:3306:3306"

Shall I put something under volumes to check the logs and save the database in the host?

BR,Austin

xu4wang commented 7 months ago

Tried below, seems the nginx log and database files are created. However, after the configuration change, the mysql db is no longer accessible by my app and pma.

version: '3.8'  
services:
  web:
    image: fbraz3/lnmp
    volumes:
      - ./app:/app/public/
      - ./nginx_logs:/var/log/nginx  
      - ./mariadb_data:/var/lib/mysql  
    ports:
      - "127.0.0.1:8081:80"
      - "127.0.0.1:3306:3306"

docker-compose logs shows MariaDB failed to start.

wp-1  |  * Restarting periodic command scheduler cron
wp-1  |  * Stopping periodic command scheduler cron
wp-1  |    ...done.
wp-1  |  * Starting periodic command scheduler cron
wp-1  |    ...done.
wp-1  |  * Restarting PHP 8.3 FastCGI Process Manager php-fpm8.3
wp-1  |    ...done.
wp-1  |  * Stopping MariaDB database server mariadbd
wp-1  |    ...done.
wp-1  |  * Starting MariaDB database server mariadbd
wp-1  |    ...fail!
wp-1  |  * Restarting nginx nginx
wp-1  |    ...done.
wp-1  |  * Restarting daemon monitor monit
wp-1  |    ...done.
wp-1  | ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (111)
xu4wang commented 7 months ago

Finnally, this one works. A named volume managed by docker should be used in Mac.

version: '3.8'
services:
  wp:
    image: fbraz3/lnmp
    volumes:
      - ./app:/app/public/
      - ./nginx_logs:/var/log/nginx 
      - my-datavolume:/var/lib/mysql  
    ports:
      - "127.0.0.1:8081:80"
      - "127.0.0.1:3306:3306"
volumes:
  my-datavolume: