Skip to content

Instantly share code, notes, and snippets.

@Yoshyn
Created March 5, 2021 19:17
Show Gist options
  • Save Yoshyn/c4d8feb0818665b4030a6eb2dec5d3ed to your computer and use it in GitHub Desktop.
Save Yoshyn/c4d8feb0818665b4030a6eb2dec5d3ed to your computer and use it in GitHub Desktop.
Docker & Sqlite3 backup. Volume manipulation
# docker build -f sqlite3.Dockerfile -t sqlite3:local .
# docker run --rm -it -v sqlite-db-volume:/db sqlite3:local my_app.db
FROM alpine:latest
RUN apk add --update sqlite
RUN mkdir /db
WORKDIR /db
ENTRYPOINT ["sqlite3"]
CMD ["my_app.db"]
# Backup
# docker run --rm -it -v sqlite-db-volume:/db sqlite3:local my_app.db .dump >> dump.sql
# OR (not using file direclty)
# docker run --rm -it -v $(pwd):/dump -v sqlite-db-volume:/db alpine:latest cp /db/my_app.db /dump
# Restore
# cat dump.sql | docker run --rm -i -v sqlite-db-volume:/db sqlite3:local my_app.db
# OR inverse operation of copy
create table test_table(id int, description varchar(10));
insert into test_table values(1, 'foo');
insert into test_table values(2, 'bar');
select * from test_table;
.exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment