Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kazu69/docker-mysql-pattern-sample
https://github.com/kazu69/docker-mysql-pattern-sample
Last synced: 19 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kazu69/docker-mysql-pattern-sample
- Owner: kazu69
- Created: 2016-01-22T11:58:32.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-23T02:50:27.000Z (almost 9 years ago)
- Last Synced: 2024-10-17T13:46:49.057Z (20 days ago)
- Language: Shell
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Initialize data and persistent in docker mysql
> This is a sample by inserting the initial data in the mysql database at the start-up docker container.
And it shows how to persist data.### require
- [virtualbox](https://www.virtualbox.org/)
- [docker-machine](https://docs.docker.com/machine/)
- [docker-compose](https://docs.docker.com/compose/)### how to
#### Introduction of initial data
Create Database and Insert initial data.
```sh
docker-compose up -ddocker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3e3ad4a65c98 dockermysql_app_server "apache2-foreground" 2 hours ago Up 8 seconds 80/tcp app_server_1
eb3e8d83aa7c mysql:5.5 "/entrypoint.sh mysql" 2 hours ago Up 2 hours 0.0.0.0:3306->3306/tcp mysql_server_1PHP_CONTAINER_NAME=app_server_1
# Connection mysql container from mysql client container.
# Mysql server and the mysql client server has been link.docker exec -t $PHP_CONTAINER_NAME mysql -u test -ppassword -h mysql -e "use sample_db; select * from personal;"
+----+------------+
| id | name |
+----+------------+
| 1 | root@local |
+----+------------+
```#### Persistence of data
```sh
docker-compose up -ddocker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3e3ad4a65c98 app_server "apache2-foreground" 2 hours ago Up 8 seconds 80/tcp app_server_1
eb3e8d83aa7c mysql:5.5 "/entrypoint.sh mysql" 2 hours ago Up 2 hours 0.0.0.0:3306->3306/tcp mysql_server_1PHP_CONTAINER_NAME=app_server_1
docker exec -t $PHP_CONTAINER_NAME mysql -u test -ppassword -h mysql -e "use sample_db; insert personal (id, name) values (2, 'admin@local');"
docker exec -t $PHP_CONTAINER_NAME mysql -u test -ppassword -h mysql -e "use sample_db; select * from personal;"
+----+------------+
| id | name |
+----+------------+
| 1 | root@local |
| 2 | admin@loca |
+----+------------+
```#### Get backup data
```sh
docker run --rm --volumes-from -v $(pwd):/backup app:latest tar czvf /backup/archive.tar.gz /var/lib/mysql
```