Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

Docker compose - share database with git

I'm quite new to docker and I try to setup my dev-environment for a simple wordpress site. So my docker-compose.yaml looks like this:

version: '3'

services:
  #Database
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment: 
        MYSQL_ROOT_PASSWORD: password
        MYSQL_DATABASE: wordpress
        MYSQL_USER: wordpress
        MYSQL_PASSWORD: wordpress
    networks:
      - my_network
    
  #Wordpress
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - '8080:80'
    restart: always
    volumes: ['./src/:/var/www/html']
    environment: 
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    networks:
      - my_network

networks:
  my_network:
volumes:
  db_data:

When i run this docker-compose, all works as expected and i know that i can now export my mysql database with:

docker exec <CONTAINER> /usr/bin/mysqldump -u root --password=root <DATABASE> > backup.sql

My Problem: I'm working on different systems and share the project using a self-hosted git (gitea). I did a lot of research and wondered why i could not find any nice way to bring also the volume db_data into git (All solutions i found do import and export database-dumps). Imo the export and import seem to be unnecessary extra steps (at least for my workflow?)

question from:https://stackoverflow.com/questions/65842555/docker-compose-share-database-with-git

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...