PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 5, 2022

[FIXED] DB in Docker container keeps getting deleted

 March 05, 2022     codeigniter, docker, mariadb, mysql     No comments   

Issue

I'm new to docekr and I'm setting up a Codeigniter docker image on my local machine bitnami/codeigniter:3

Everything works fine but the mysql container looses it's DB and all the data everytime I perform sudo docker-compose down

This is docker-compose file

version: '3.3'
services:
 myapp:
  image: docker.io/bitnami/codeigniter:3
  container_name: app-backend
  ports:
   - '8000:8000'
 volumes:
   - '.:/app'
depends_on:
  - mariadb
mariadb:
 image: docker.io/bitnami/mariadb:10.3
 container_name: app-marriadb
 volumes:
   - app_dbdata:/var/lib/mysql
 environment:
   MYSQL_ROOT_PASSWORD: root
   MYSQL_DATABASE: app_db
 ports:
   - '3307:3306'
 environment:
   - ALLOW_EMPTY_PASSWORD=yes
volumes:
 app_dbdata:

I tried multiple possiblities but not sure where I'm going wrong. My OS is Ubuntu 18.04


Solution

The bitnami/mariadb image uses a different path inside the container for its database storage. Quoting the "Persisting your database" section of its Docker Hub page:

For persistence you should mount a directory at the /bitnami/mariadb path. If the mounted directory is empty, it will be initialized on the first run.

So in your Compose setup, specify that path as the mount directory:

version: '3.8'
services:
  mariadb:
    volumes:
      - app_dbdata:/bitnami/mariadb # <-- not /var/lib/mysql
volumes:
  app_dbdata: # unchanged


Answered By - David Maze
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing