I had sqlite database with some sort of tables on my localhost and i wanted to copy and paste that database to my server which runs on docker. I created paths like this:
db_data: there is my sqlite database which i want to run in my django project. web: there is my whole django project
in my docker-compose.yml i writed this volume:
version: "3"
services:
web:
build: ./web/
ports:
- "8001:8001"
volumes:
- ./web:/code
- /home/cosmo/db_data/db.sqlite3:/code/db.sqlite3
command: python manage.py runserver 0.0.0.0:8001
So i thik that docker will get database in my db_data and will make volume inside my web folder (in my project. There i had database on my localhost so it wouldnt be problem.) But i will paste here settings.py:
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
So when i will open my db.sqlite3 inside db_data every tables and content are there, but when i will run container the db.sqlite3 in my project folder (web) is empty.
When i will run docker ps command there is no database container maybe this is the problem i dont know. I have there only:
in the red circle is my django container. So when i will run my server and try to login every account from the database is unknown. So I think that container works with that empty db in my project. Someone please has any solution? Thanks.
/code/db.sqlite3
but put it in its own folder then you can reference that in your settings file. You could see list of volumes using docker volume ls
(assumes Docker 1.8+)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With