Skip to content

Commit

Permalink
Merge pull request jwasham#7 from tinpee/master
Browse files Browse the repository at this point in the history
Docker backup and restore data
  • Loading branch information
jwasham authored Oct 19, 2016
2 parents 35589f7 + e262c74 commit 89b56b4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ MAINTAINER Tinpee <[email protected]>

ADD . /src
WORKDIR /src
RUN pip install flask gunicorn \
&& cp cards-jwasham.db cards.db
RUN pip install flask gunicorn

COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh

VOLUME /src/db

EXPOSE 8000
CMD ["/entrypoint.sh"]

Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ __Make sure you already installed [docker](https://www.docker.com)__
1. Build image: `docker build . -t cs-flash-cards`
1. Run container: `docker run -d -p 8000:8000 --name cs-flash-cards cs-flash-cards`
1. Go your browser and type `http://localhost:8000`
1. To back up your cards db, run `docker cp cs-flash-cards:/src/cards.db /path/to/save`
__If you already had a backup file `cards.db`. Run following command:__
*Note: We don't need to rebuild image, just delete old container if you already built.*
`docker run -d -p 8000:8000 --name cs-flash-cards -v :<path_to_folder_contains_cards_db>:/src/db cs-flash-cards`
`<path_to_folder_contains_cards_db>`: is the full path contains `cards.db`
Example: `/home/tinpee/cs-flash-cards/db`, and `cards.db` is inside this folder.
For convenient, if you don't have `cards.db`, this container will auto copy a new one from `cards-jwasham.db`. So you don't need to `initdb`
__How to backup data ?__
We just need store `cards.db` file, and don't need any sql command.
- If you run container with `-v <folder_db>:/src/db` just go to `folder_db` and store `cards.db` anywhere you want.
- Without `-v flag`. Type: `docker cp <name_of_container>:/src/db/cards.db /path/to/save`
__How to restore data ?__
- Delete old container (not image): `docker rm cs-flash-cards`
- Build a new one with `-v flag`:
`docker run -d -p 8000:8000 --name cs-flash-cards -v :<path_to_folder_contains_cards_db>:/src/db cs-flash-cards`
- Voila :)
*Happy learning!*
5 changes: 5 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/bin/bash

if [ ! -f /src/db/cards.db ]; then
mkdir -p /src/db
cp cards-jwasham.db /src/db/cards.db
fi

export CARDS_SETTINGS=/src/config.txt
gunicorn --bind 0.0.0.0:8000 flash_cards:app
2 changes: 1 addition & 1 deletion flash_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Load default config and override config from an environment variable
app.config.update(dict(
DATABASE=os.path.join(app.root_path, 'cards.db'),
DATABASE=os.path.join(app.root_path, 'db', 'cards.db'),
SECRET_KEY='development key',
USERNAME='admin',
PASSWORD='default'
Expand Down

0 comments on commit 89b56b4

Please sign in to comment.