|
| 1 | +# Application Deployment Using Docker |
| 2 | +1. **Docker Command for Build,Save,Load image** |
| 3 | +2. **Create Docker Network** |
| 4 | +2. **Run Docker For Database** |
| 5 | +3. **Run Docker For Redis** |
| 6 | +4. **Run Docker For ML Model** |
| 7 | +5. **Run Docker For One-time Application Migration** |
| 8 | +6. **Run Docker For Application (Web & Worker)** |
| 9 | +7. **Run Docker For Nginx (If required)** |
| 10 | + |
| 11 | +**NOTE: If docker command raise issue then use sudo** |
| 12 | + |
| 13 | +### Docker Command for Build,Save,Load image |
| 14 | +```ssh |
| 15 | +docker build -t tage_name . |
| 16 | +docker save tage_name > tage_name.tar |
| 17 | +docker load --input tage_name.tar |
| 18 | +``` |
| 19 | + |
| 20 | +### Create Docker Network |
| 21 | +```ssh |
| 22 | +docker network create application_network |
| 23 | +``` |
| 24 | + |
| 25 | +### Run Docker For Database |
| 26 | +```ssh |
| 27 | +docker run -d --name postgres --network application_network -e POSTGRES_USER={{DB_USERNAME}} -e POSTGRES_PASSWORD={{DB_PASSWORD}} -e POSTGRES_DB={{DB_NAME}} -e PGDATA=/var/lib/postgresql/data/pgdata -v ./postgresql/data:/var/lib/postgresql/data/pgdata postgres:14 |
| 28 | +``` |
| 29 | + |
| 30 | +### Run Docker For Redis |
| 31 | +```ssh |
| 32 | +docker run -d --name redis --network application_network redis:7 |
| 33 | +``` |
| 34 | + |
| 35 | +### Run Docker For ML Model |
| 36 | +```ssh |
| 37 | +docker run -d --name layoutlmv2 --network application_network --env-file ./.env -v ./layoutlmv2/model:/opt/ml/model entities:latest |
| 38 | +docker run -d --name detr --network application_network --env-file ./.env -v ./detr/model:/opt/ml/model table:latest |
| 39 | +``` |
| 40 | + |
| 41 | +### Run Docker For One-time Application Migration |
| 42 | +```ssh |
| 43 | +docker run --rm --name application_migrate --network application_network --link postgres --link redis --env-file ./.env application:latest python manage.py migrate_schemas |
| 44 | +docker run --rm --name application_public --network application_network --link postgres --link redis --env-file ./.env application:latest python manage.py make_public_tenant |
| 45 | +``` |
| 46 | + |
| 47 | +### Run Docker For Application (Web & Worker) |
| 48 | +```ssh |
| 49 | +docker run -d --name application_webserver --network application_network --link postgres --link redis --env-file ./.env --entrypoint ./custom_entrypoint.sh -v ./custom_entrypoint.sh:/home/application/custom_entrypoint.sh -v ./media:/home/application/media -v ./static:/home/application/static -p 8000:8000 application:latest |
| 50 | +``` |
| 51 | + |
| 52 | +#### Custom Entrypoint (name: custom_entrypoint.sh) |
| 53 | +```ssh |
| 54 | +#!/bin/bash |
| 55 | +python manage.py runserver 0.0.0.0:8000 & celery -A application_project worker -l INFO -c 2 |
| 56 | +``` |
| 57 | + |
| 58 | +### Run Docker For Nginx (If required) |
| 59 | +```ssh |
| 60 | +docker run -d --name nginx_server --network application_network -v ./nginx.conf:/etc/nginx/nginx.conf -v ./certs:/etc/nginx/certs/ -v ./static:/etc/nginx/static/ -p 443:443 nginx:latest |
| 61 | +``` |
| 62 | + |
| 63 | +#### Nginx Conf (name: nginx.conf) |
| 64 | +```ssh |
| 65 | +events { |
| 66 | + worker_connections 1024; |
| 67 | +} |
| 68 | +
|
| 69 | +http { |
| 70 | + upstream django { |
| 71 | + server application_webserver:8000; |
| 72 | + } |
| 73 | + |
| 74 | + server { |
| 75 | + listen 443 ssl; |
| 76 | + server_name {{tenant_domain}}; |
| 77 | +
|
| 78 | + ssl_certificate /etc/nginx/certs/glib/certificate.crt; |
| 79 | + ssl_certificate_key /etc/nginx/certs/glib/private.key; |
| 80 | + |
| 81 | + ssl_protocols TLSv1.2 TLSv1.3; |
| 82 | + ssl_prefer_server_ciphers on; |
| 83 | + ssl_ciphers HIGH:!aNULL:!MD5; |
| 84 | + |
| 85 | + #location /static/ { |
| 86 | + # alias /etc/nginx/static/; |
| 87 | + #} |
| 88 | +
|
| 89 | + location / { |
| 90 | + proxy_pass http://application_webserver:8000; |
| 91 | + # proxy_set_header Host {{tenant_domain}}; (if required) |
| 92 | + proxy_set_header X-Real-IP $remote_addr; |
| 93 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 94 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 95 | + } |
| 96 | + client_max_body_size 250M; |
| 97 | + } |
| 98 | + |
| 99 | + |
| 100 | + server { |
| 101 | + listen 443 ssl; |
| 102 | + server_name {{admin_domain}}; |
| 103 | +
|
| 104 | + ssl_certificate /etc/nginx/certs/admin/certificate.crt; |
| 105 | + ssl_certificate_key /etc/nginx/certs/admin/private.key; |
| 106 | + |
| 107 | + ssl_protocols TLSv1.2 TLSv1.3; |
| 108 | + ssl_prefer_server_ciphers on; |
| 109 | + ssl_ciphers HIGH:!aNULL:!MD5; |
| 110 | + |
| 111 | + #location /static/ { |
| 112 | + # alias /etc/nginx/static/; |
| 113 | + #} |
| 114 | +
|
| 115 | + location / { |
| 116 | + proxy_pass http://application_webserver:8000; |
| 117 | + # proxy_set_header Host {{admin_domain}}; (if required) |
| 118 | + proxy_set_header X-Real-IP $remote_addr; |
| 119 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 120 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 121 | + } |
| 122 | + client_max_body_size 250M; |
| 123 | + } |
| 124 | +} |
| 125 | +``` |
0 commit comments