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/mariadbpath. 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
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.