-
Notifications
You must be signed in to change notification settings - Fork 10
docker mysql persistent data
bohyeon edited this page Dec 12, 2019
·
1 revision
-
/my/own/datadir:/var/lib/mysql
- 지정된 디렉토리 (디렉토리 생성 후 접근권한도 줘야한다고 한다.)
-
my_data:/var/lib/mysql
- docker volume 이용
- docker-compose.yml내에 volumes 항목을 작성해줘야함
-
Let Docker manage the storage of your database data by writing the database files to disk on the host system using its own internal volume management . This is the default and is easy and fairly transparent to the user. The downside is that the files may be hard to locate for tools and applications that run directly on the host system, i.e. outside containers.
- Create a data directory on the host system (outside the container) and mount this to a directory visible from inside the container . This places the database files in a known location on the host system, and makes it easy for tools and applications on the host system to access the files. The downside is that the user needs to make sure that the directory exists, and that e.g. directory permissions and other security mechanisms on the host system are set up correctly.
db:
build:
context: ./mysql
dockerfile: ../docker/mysql.Dockerfile
environment:
ports:
- "3306:3306"
networks:
- backend
volumes:
- mysql_data:/var/lib/mysql
volumes:
mysql_data:
$ docker exec some-mysql sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > /some/path/on/your/host/all-databases.sql
# docker container에서 직접 명령을 내린다면
$ mysqldump --databases mydatabase -uroot -p"$MYSQL_ROOT_PASSWORD"' > /some/path/on/your/host/all-databases.sql
- dump한 .sql 파일을 admin 페이지를 통해서 다운받을 수 있을까?
- https://stackoverflow.com/questions/30921435/nodejs-backup-mysql-database
- https://expressjs.com/en/4x/api.html#res.sendFile
$ docker-compose down --volumes
$ docker-compose down -v
# volume
$ docker volume prune
# image
$ docker image prune
# container
$ docker rm [OPTIONS] CONTAINER [CONTAINER...]
- Where is MySQL database stored - Developer’s hints and tips
- MySQL :: MySQL 8.0 Reference Manual :: 5.2 The MySQL Data Directory
- Unix / Linux - File System Basics - Tutorialspoint
- Docker Hub - where to Store Data
- docker volume | Docker Documentation
- docker rm | Docker Documentation
- Docker Hub - Creating database dumps
#docker #mysql #docker-compose