I have been interacting with Docker for a while. For all of its great promise, tutorial and books, no one seems to be talking about how to actually use Docker in reality. I've found many examples, running Nginx with a static website. But there's never a complete workflow.
I have a docker composer system, both develop and production. It's in a git repo. I can clone it into any server, run a simple script, a docker container spins up and I have a website. Or at least a piece of one. The stack is basically Django + Gunicorn + Nginx + postgres all dockerized .
Yet, that's where docker fails for me. The container needs data, from a database and some file (images, etc) that are currently data volumes. If I spin the container down, that data is lost, necessitating loading of the data when container runs. My development consists of improving the front end and back end.
I have yet to understand how to actually push this to a real system. People talk about docker swarm and Kubernetes to deploy applications. Where is the actual data? How is that handled?. I currently have to have it in my repository, then run manual commands to load the postgres database and copy the static files over.
My goal is to actually automate things and make it easier to deploy (as close to one click push as possible). Yet every tutorial starts talking about the details of docker which everyone repeats ad nauseum (how to build an image, the scripts, etc). It's incredibly frustrating.
Is docker only used to setup the main architecture? Where is all the specific application data stored? How is that tracked and developed? Am I supposed to have an architecture where I can edit a repo and push it to the server?
I also have issues where the container takes time to spin up. How does this work in production? Do I push it to another server then change the IP addresses? Or do I put the new docker in the same server and do something? (I assume IP ports will conflict)
What about when there's a reboot of the server running the container? They don't start back up.
Thank you for any help
Here's my docker compose file. As per many recommendations online, uses volumes, environment variables, etc etc. It runs, but it's not a movable container. Even when I call down without the -v (for volumes) they go down and don't stay there when I do another up command
docker-compose -f docker-compose.prod.yml up -d --build
docker-compose -f docker-compose.prod.yml down -v
This is the compose file
version: '3.7'
services:
web:
build:
context: ./app
dockerfile: Dockerfile.prod
command: gunicorn awebsite.wsgi:application --bind 0.0.0.0:8000
volumes:
- static_volume:/home/app/web/staticfiles
- media_volume:/home/app/web/mediafiles
expose:
- 8000
env_file:
- ./.env.prod
depends_on:
- db
db:
image: postgres:13.4-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- ./.env.prod.db
nginx:
build: ./nginx
volumes:
- static_volume:/home/app/web/staticfiles
- media_volume:/home/app/web/mediafiles
ports:
- 80:80
depends_on:
- web
volumes:
postgres_data:
static_volume:
media_volume: