{"id":13581614,"url":"https://github.com/benbjohnson/litestream-docker-example","last_synced_at":"2025-03-17T06:31:31.877Z","repository":{"id":39747810,"uuid":"373645468","full_name":"benbjohnson/litestream-docker-example","owner":"benbjohnson","description":"An example of using Litestream within a Docker container.","archived":false,"fork":false,"pushed_at":"2022-05-15T13:42:13.000Z","size":13,"stargazers_count":102,"open_issues_count":0,"forks_count":13,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-15T23:56:14.414Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benbjohnson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-03T21:27:18.000Z","updated_at":"2025-03-05T22:49:55.000Z","dependencies_parsed_at":"2022-07-31T23:38:01.925Z","dependency_job_id":null,"html_url":"https://github.com/benbjohnson/litestream-docker-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbjohnson%2Flitestream-docker-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbjohnson%2Flitestream-docker-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbjohnson%2Flitestream-docker-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbjohnson%2Flitestream-docker-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benbjohnson","download_url":"https://codeload.github.com/benbjohnson/litestream-docker-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243847062,"owners_count":20357317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T15:02:07.943Z","updated_at":"2025-03-17T06:31:31.296Z","avatar_url":"https://github.com/benbjohnson.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"Litestream \u0026 Docker Example\n===========================\n\nThis repository provides an example of running a Go application in the same\ncontainer as Litestream by using the built-in subprocess execution. This allows\ndevelopers to release their SQLite-based application and provide replication in\na single container.\n\n\n## Usage\n\n### Prerequisites\n\nTo test this locally, you'll need to have an S3-compatible store to connect to.\nPlease see the [Litestream Guides](https://litestream.io/guides/) to get set up\non your preferred object store.\n\nYou'll also need to update the replica URL in `etc/litestream.yml` in this\nrepository to your appropriate object store.\n\nYou'll also need to set your object store credentials in your shell environment:\n\n```sh\nexport LITESTREAM_ACCESS_KEY_ID=XXX\nexport LITESTREAM_SECRET_ACCESS_KEY=XXX\n```\n\n\n### Building \u0026 running the container\n\nYou can build the application with the following command:\n\n```sh\ndocker build -t myapp .\n```\n\nOnce the image is built, you can run it with the following command. _Be sure to\nchange the `REPLICA_URL` variable to point to your bucket_.\n\n```sh\ndocker run \\\n  -p 8080:8080 \\\n  -v ${PWD}:/data \\\n  -e REPLICA_URL=s3://YOURBUCKETNAME/db \\\n  -e LITESTREAM_ACCESS_KEY_ID \\\n  -e LITESTREAM_SECRET_ACCESS_KEY \\\n  myapp\n```\n\nLet's break down the options one-by-one:\n\n- `-p 8080:8080`—maps the container's port 8080 to the host machine's port 8080\n  so you can access the application's web server.\n\n- `-v ${PWD}:/data`—mounts a volume from your current directory on the host\n  to the `/data` directory inside the container.\n\n- `-e REPLICA_URL=...`—sets an environment variable for your replica. This is\n  used by the startup script to restore the database from a replica if it\n  doesn't exist and it is used in the Litestream configuration file.\n\n- `-e LITESTREAM_ACCESS_KEY_ID` \u0026 `-e LITESTREAM_SECRET_ACCESS_KEY`—passes\n  through your current environment variables for your S3 credentials to the\n  container. You can also use `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`\n  instead.\n\n\n### Testing it out\n\nIn another window, you can run:\n\n```sh\ncurl localhost:8080\n```\n\nand you should see:\n\n```\nThis server has been visited 1 times.\n```\n\nEach time you run cURL, it will increment that value by one.\n\n\n### Recovering your database\n\nYou can simulate a catastrophic disaster by stopping your container and then\ndeleting your database:\n\n```\nrm -rf db db-shm db-wal .db-litestream\n```\n\nWhen you restart the container again, it should print:\n\n```\nNo database found, restoring from replica if exists\n```\n\nand then begin restoring from your replica. The visit counter on your app should\ncontinue where it left off.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenbjohnson%2Flitestream-docker-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenbjohnson%2Flitestream-docker-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenbjohnson%2Flitestream-docker-example/lists"}