question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Persistent Data - Docker

See original GitHub issue

This is a great app! Thanks for all the hard work to make it possible. I have one issue that i am trying to resolve. I am running the babybuddy app via docker and I cannot make the data persistent between server restarts. What directories do I need to have as persistent volumes in order to get this to work?

This is my docker-compose file with the volumes I declare to create persistent data. What am I missing? Thanks!

docker-compose.yml
services:
  db:
    image: postgres
    volumes:
      - db:/var/lib/postgresql
  app:
    env_file: docker.env
    build: .
    command: gunicorn -c /app/gunicorn.py babybuddy.wsgi
    volumes:
      - baby_data:/app
    ports:
      - "8000:8000"
    environment:
      - VIRTUAL_HOST=**************
      - LETSENCRYPT_HOST=**************
      - LETSENCRYPT_EMAIL=**************
      - VIRTUAL_PORT=8000
    depends_on:
      - db
    networks:
      - proxy-tier
      - default

volumes:
  baby_data:
  db:

networks:
  proxy-tier:
    external:
      name: webproxy

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

2reactions
djmwjcommented, Jun 1, 2018

Thanks for looking into it. I have figured it out. the postgresql db image uses /var/lib/postgresql/data as the default data location. In order to have a persistent db, you must use a named volume for this location. Additionally, in order to avoid re-migrating and collectingstatic content every time, I added /app as a named volume as well.

So for the default docker-compose, it would look like:

docker-compose.yml
version: "2"

services:
  db:
    image: postgres
    volumes: 
       - db:/var/lib/postgresql/data
  app:
    env_file: docker.env
    build: .
    command: gunicorn -c /app/gunicorn.py babybuddy.wsgi
    ports:
      - "8000:8000"
    depends_on:
      - db
    volumes:
      - baby_data:/app

volumes:
   db:
   baby_data:
1reaction
cdubzcommented, May 17, 2018

I played around with this but unforntaley didn’t get anywhere either. Docker is a bit of a beast. I’ll leave this open for a bit and would love to hear if you manage to figure out proper config. Sorry I couldn’t be more helpful!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Persist the DB - Docker Documentation
Persist the todo data · Create a volume by using the docker volume create command. · Stop and remove the todo app container...
Read more >
Volumes - Docker Documentation
Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. While bind mounts are dependent on the directory ......
Read more >
How to persist data in Docker: Volumes - TinyStacks
Volumes are the preferred mechanism for persisting data generated by and used by Docker containers, for the reasons given before .
Read more >
Why Containers Miss a Major Mark: Solving Persistent Data in ...
Docker's solution. There is no getting away from it, data needs to be externalized and persisted outside the container and not maintained as...
Read more >
Persist data in a container app using volumes in VS Code
Persist your todo data using named volumes · Create a volume by using the docker volume create command. · Under CONTAINERS, select getting-start ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found