Great Thanks for this video! It was very hard to digest for the first deployment, but carefully breaking down and playing around with each step help me a lot to deeper understand what is going on and why I should use a more complex approach
This is the best tutorial I have seen on deploying docker containers, I applied similar method to deploying on Linode. I learned a lot and I can't wait to get the full course. Great work Mike
Great video Mark, keep up the good work! I like the way you slowly explain what you do with no extra unnecessary "decorative" remarks. Hope to have a pint of beer with you sometime in London mate!
I am so thankful for your video Mark. You are an excellent, EXCELLENT teacher. One of the best tutorials for CS on UA-cam for any subject! Keep up the wonderful work and I will be praying for your channel to grow even more!
Hey Mark, really appreciate for your tutorial. This is the exactly video I was looking! It was so detailed and you explain everything so well. Thank you!❤
Hey Mark, in my opinion one of the best tutorials on youtube. Thank u very much for your detailed explaination. This helped me a lot for our university project. kind greetings from germany
just about completed this now :) Most recent working versions are: Dockerfile: python:3.11-alpine3.15 docker-compose.yml / docker-compose-deploy.yml - Python 3.11 - Image: postgres:15-alpine Requirements.txt: Django==4.2 psycopg2==2.9.6 uWSGI==2.0.21
Yo Mark! I purchased your advanced Django course on Udemy a couple of years ago and it's the best damn course on the subject. Perhaps the only thing missing was how to deploy the project to AWS using Docker containers, so thanks for this video! Keep up the good work, my dude.
@@LondonAppDeveloper thanks a lot in advance for this video. I have a complete django project to deploy with a e-commerce, models, and many IOt features . I have tried in many time to deploy but didn't work or worked only launching a runserver into a instance now i am following your tutorial to see whether it works on aws . Thanks for your interesting videos. All the best regards
I’ve mashed the subscribe and like buttons! An excellent tutorial - I’ve been wondering about this topic for a while. I’ve learnt an enormous amount. If I get stuck with it I’ll either be doing the full course or contacting you direct for some consulting. Great work, thank you 👍
@@LondonAppDeveloper im trying to connect my react app to my EC2 instance but it fails to connect over HTTPS. It works perfectly fine over HTTP. Have been looking for solutions but failed miserably. Im not sure if the docker setup is the issue or not. Any recommendations on where to look?
Thanks for the excellent tutorial Mark. successfully tested the deployment on the production server locally but, have some problem in the development, particularly in the " MEDIA_ROOT='/vol/static/media' ", it gives me Permission denied error and was not mounted on the "/data/web", but when using " MEDIA_ROOT='vol/static/media/' ", there is no error and can saved the media in "app/app/vol/static/media" and was not mounted in "/data/web/". anyway, the production deployment was great locally, haven't tested it yet in the actual production server, thanks Mark. keep it up.
@@nicolasqueiroga6455 maybe is this: When docker create a data/web to our system it creates with user roots permissions, so when Django app tries to save the file can't. so just change the permissions data/web file to your current user.
I'm trying to deploy this to Heroku and I am stuck on this - Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch I know I'm supposed to get the port it's served on using an ENV variable that Heroku randomly assigns it, but my understanding of Nginx and docker isn't sufficient enough for me to figure out where to change what. Does anyone have experience with this?
thank You very much for the class but I ran into a problem when running docker-compose build and here is response i got Error while fetching server API version: (2, 'CreateFile', 'The system cannot find the file specified.') [9676] Failed to execute script docker-compose
Great tutorial thanks. I have a few questions/Notes. 1. If you use -volumes: ./app:/app Why do you create a directory 'app' and then name your project 'app' and put it inside 'app' directory ? It is so confusing. 2. where is /py/bin/ directory? inside docker container. It is the default in the 3.9-alphine3.14 image? 3. I'm using pipenv and do not understand about the PATH env variable. for what you need to change PATH = ... 4. 59:52 need to add ALLOWED_HOSTS = ["0.0.0.0"] 5. 1:14:10 PermissionError: [Errno 13] Permission denied: '/vol/web/media' . Answer: need to have permissons on all your local files. 2:00:00 db_1 | Error: Database is uninitialized and superuser password is not specified. app_1 | Database unavailable, wait 1 second... I'm stuck on this mistake ERROR: unable to select packages: postgresql-clien (no such package): required by: world[postgresql-clien] ERROR: Service 'app' failed to build : I was trying to use pipenv RUN python -m venv /py && \ /py/bin/pip install --upgrade pip && \ /py/bin/pip install pipenv && \ apk add --update --no-cache postgresql-clien && \ apk add --update --no-cache --virtual .tmp-deps \ build-base postgresql-dev musl-dev linux-headers && \ pipenv shell && \ apk del .tmp-deps && \ adduser --disabled-password --no-create-home app && \ mkdir -p /vol/web/static && \ mkdir -p /vol/web/media && \ chown -R app:app /vol && \ chmod -R 755 /vol && \ chmod -R +x /scripts if occurs problems with pipenv and psql pipenv install psycopg2-binary After 2 weeks tryings I think I will try to deploy on DigatalOcean. Because I think for new one it is hard.
Hey, for the permissions error, what do you mean by "need to have permissons on all your local files. ". It would be nice if you could offer specific steps on how to achieve that.
If anyone is facing the PermissionError: [Errno 13] Permission denied: '/vol/web/media' issue, here's the fix:- TLDR fix - enter this command in the terminal from inside the root folder - "sudo chmod -R a+rwx ./data" Explanation - So, in the docker-compose.yml, because we added ./data/web:/vol/web, under volumes, when we upload a file, it uses the same app user specified in the Dockerfile to write the uploaded file to the ./data folder. So making the /data folder writable fixes the issue
Will there be any need for the wait_for_db command if postgresql is defined before the app service? I don't really know docker but from the outputs it seems to run from top to bottom.
This is a great tutorial, so I definitely liked and subscribed. I'm not a fan of the deployment method (github actions would be nicer), but the way you configured docker for local django development and introducing env variables seems to be the best way I've seen, and I think the nginx container handling static is has its advantages over S3 for smaller sites. But that's the beauty of tutorials, you don't have to adopt everything exactly the same. I do have a couple of questions more down to Django development though: What I envision with Django for CMS kind of sites is that I want to develop a starting point with my core app locally, but have it so my pages (like "about" and "contact us" kind of pages) are built out without hard coding content, so I'd have a model in the core app called Page. The problem this introduces though is that a database migration won't populate the content from dev to prod. So I'd need a deployment step that backs up the local db and restores it to the prod db. Is this an approach you'd take, or would you try to leave database stored content as something that shouldn't be in each environment? My other question is down to the wait_for_db command. Is there a reason this is in an app rather than the actual project folder where the settings.py file is located?
I am stuck making migrations. I have a Mac and use PostgreSQL. I want to use my local machine database, not a Docker image. I cannot connect to that DB. Any help?
How can I solve this error? After giving permission to the vol why its giving error? PermissionError: [Errno 13] Permission denied: '/vol/web/media'. I have followed your video as well as blog.
If anyone is facing the PermissionError: [Errno 13] Permission denied: '/vol/web/media' issue, here's the fix:- TLDR fix - enter this command in the terminal from inside the root folder - "sudo chmod -R a+rwx ./data" Explanation - So, in the docker-compose.yml, because we added ./data/web:/vol/web, under volumes, when we upload a file, it uses the same app user specified in the Dockerfile to write the uploaded file to the ./data folder. So making the /data folder writable fixes the issue
Very good tutorial! Hope you still take questions. I have only one issue confusing me and this relates to line 23 of the Dockerfile - the app:app. I assume the 2nd app is the added user. What does the first app refer to?
psycopg2-binrary is not recommended for production as mentioned on their pip page: pypi.org/project/psycopg2-binary/ "The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources.". If you need to install it directly for dev only then it's fine, but my philosophy is to use Docker to match both local dev/prod as closely as possible.
Awesome tutorial, I've watched it till the end and everything worked. But when I came back to this project after a week and tried to launch it didn't connect me to the website and throw err_connection_timed_out error in browser. I've checked and replaced host address with new one which was provided by ec2 (after relaunching instance). What could be wrong?
@@LondonAppDeveloper Thanks for the answer but I've already changed the ALLOWED_HOSTS variable via "vi .env", moreover I tried to use Elastic IP adress to keep IP adress during sessions but that didn't work. I've also tried to create another instance and deploy project there but still the same result... After a while there were some queries in the console but all of them were with "HTTP 400" and they weren't connected with my attempts to reach the website. I've spent a day and a half to find information but there was none.
@@RuslanSkiraUkraine , I've solved it in a bit odd way. So when you open your ec2 instance in browser you can see the Public IPv4 address and Public IPv4 DNS with buttons "open address". I've always tried to open my website via these buttons but never succeeded (err_connection_timed_out). But then I just copied and pasted IPv4 and all of a sudden everything worked as usual. I think it's because when you press the button it opens website using https protocol but if you copy and paste the actual ip it will be opened with http. Hope this helps.
Best tutorial I have seen about django +. container + deployment. Really appreciated. I deployed an app using it. maybe could be interesteing to explaing it using asgi instaed of wsgi, for example in my app I'm using django channels to use websockets and I had to use asgi, how we can deploy that to production. thanks
db_1 | 2022-01-20 10:09:47.641 UTC [67] DETAIL: Password does not match for user "approotuser". db_1 | Connection matched pg_hba.conf line 99: "host all all all md5" db_1 | 2022-01-20 10:09:48.645 UTC [68] FATAL: password authentication failed for user "approotuser" db_1 | 2022-01-20 10:09:48.645 UTC [68] DETAIL: Password does not match for user "
Hello London App developer, I have an issue whenever I run the command "docker-compose -f docker-compose-deploy.yml up" I run into th django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please suppl y the NAME or OPTIONS['service'] value." Any help rendered I will be so appreciative
Hello! You didn’t tell how to resolve the issue of Not found, that happened almost in the end of video. please let me know that how to do port mapping in docker-compose-deploy.yml, only admin endpoint is working. i want to extend this website by adding more different thing. please reply and help me with it
Can you tell about how to handle the "502 Bad Gateway nginx" error. server runs on a digital ocean droplet. I tried to access the server via droplets public ip
Thank you thank you thank you !!!!! This has been great fun ! Had some trouble with the MEDIA_ROOT needing to be 'vol...' and not '/vol...' but aside from that smooth sailing :) Now I can make my best friend a webapp for Xmas !!
Hi Mark! Please let me know how to do port mapping in order to scale up this website. You just worked on admin url, anything other url doesn’t work. It say thay “Not found”.
If anyone is facing the PermissionError: [Errno 13] Permission denied: '/vol/web/media' issue, here's the fix:- TLDR fix - enter this command in the terminal from inside the root folder - "sudo chmod -R a+rwx ./data" Explanation - So, in the docker-compose.yml, because we added ./data/web:/vol/web, under volumes, when we upload a file, it uses the same app user specified in the Dockerfile to write the uploaded file to the ./data folder. So making the /data folder writable fixes the issue
"sudo chmod -R a+rwx ./data" alone didn´t fix the issue in my case. I also had to change the ownership from ROOT to MY_USER by executing "sudo chown -R MY_USER:MY_USER ./data". Only then it worked!
@@humbertocueva3815 just cd into the path where your project exists. Once you are inside the project folder that's what is called the root folder. Basically which ever folder the .data folder exists. If you're a newbie, then just open the project folder in vscode and select new terminal from the top menu and it will launch the terminal directly in the root folder of the project. From there you can directly enter the command. If it doesn't work just type ls -al and make sure that the .data folder exists within the folder you're in.
I'm a pretty late, but I wanted to add to this to help future people figure out this problem for themselves. I'm using bash, and for me personally, only changing ownership was necessary . When django automatically creates the ./data/web/ path, the permission types for these directories were the same as all the other directories in the project folder, which for me is 755 (that's rwxr-xr-x for those unacquainted). You can check by "typing ls -al" from the project's root directory. The real problem is that the /data/web directories are given "root" permissions instead of user permissions (if so, it will be indicated by "root root" in the list instead of "[user] [user]" like eveything else. So I believe simply starting from the root folder and running "sudo chown -R [user]:[user] data/" (and only this) like in Oliver's post would be all that's necessary for most people, unless they have more restrictive permission types set up for their project directory. If the latter is the case, subsequently running "sudo chmod -R 775 /data" from the project's root directory will suffice. If security isn't a concern, you can just use Ragav Y's version of the chmod command in the original message to nuke it from orbit. I just wanted to add that the core issue is likely the owner of the directories, not the permission types, but your mileage may vary.
Great question. I'm going to make another tutorial about SSL. The way to do it is like this: 1) Procure SSL certificates, 2) Update NGINX config to add SSL support, 3) Update the Docker Compose config and security groups to allow access via port 443, 4) Add a volume to the NGINX service which maps the server directory containing the SSL certs to the directory NGINX is configured to find them. It would also be possible to use Let's encrypt by adding another service to the deployment docker compose which runs the agent that updates the certs. I expect this would involve mapping a volume for the certs and a volume for the refresh keys that I believe needs to be served via NGINX. I need to spend some time figuring it out myself before I create a guide on it :)
@@LondonAppDeveloper Thank you so much for taking the time to answer. I will give the first option a try. You have no idea how much value you are offering to the community!
Thanks just suscribed!. Do you always lose the data in database when deploying? how can I make it so that i dont. Just starting and i will like to dockerize a project that is already deployed.
Hi Mark. Excellent videos tutorial. I tried following every step in your video but unfortunately i met error when i run command : docker-compose run --rm app sh -c "django-admin startproject app ." sh: django-admin: not found (Error : 127) I stop the tutorial since i have this issue. Please advise. Thank you.
Hello Mark, thank you for this great course it is short and precise. I would like to request if you have a specific course on handling static files. I will greatly appreciate it.
Thanks a lot for the lessons! you have the best content! I have a question, did we write the “migrate” command in the script, and in the case of development, do we have to execute the “makemigrations” command manually? Or can this one be automated as well? for example to register in “Dickerfile”?
When I run the command ‘’’ docker-compose -f docker-compose-deploy.yml down - -volumes ‘’’ I run into errors that the specified file is not found. And when I run “ls” the file isn’t displayed What could be the problem
I am having trouble doing the docker compose build, because I have pandas on the requirements, do you happen to know how to solve it? I have been trying to solve it for the whole week and I can't find any solutions. Thank you!
Not used Lightsail myself but I think it's just like Digital Ocean (you buy a VM and get access to it?)... Answer is probably yes, but of course some of the steps will be different. Not sure if Lightsail gives the option to use the Amazon Linux 2 AMI? The project setup and deployment part should work the same.
Why shouldn't we use "sudo useradd app" instead of "adduser --disabled-password --no-create-home app"? First command wouldn't create home directory and password by default
Brother I have an issue Can you help me out please Whenever I run the command “ docker-compose -f docker-compose-deploy.yml” I run into errors that settings.DATABASES is improperly configured
Hi, first of all thank you for this great video! Second, I have a question regarding named volumes. static-data volume is populated by the app service, then this volume is used by the proxy service. Is the volume sourced by the app service and not by the proxy because the proxy depends on the app?
The volume is not necessarily sourced by either container. The volume is the volume, and it's shared with the two containers that need the data. Apologies if I misunderstood the question.
2.5 hours of pure information and experience. Thank you so much.
Thanks for the kind words, happy to hear it was useful.
Great Thanks for this video! It was very hard to digest for the first deployment, but carefully breaking down and playing around with each step help me a lot to deeper understand what is going on and why I should use a more complex approach
THIS. I can finally replace all my hacky docker workarounds and understand what I'm actually doing. Mark, you're the best
Thanks mate, that's kind.
This is the best tutorial I have seen on deploying docker containers, I applied similar method to deploying on Linode. I learned a lot and I can't wait to get the full course. Great work Mike
Thank you sir!
Thank you Mark! Appreciated for the video!
Hey Weihao, thanks so much, this is my first Super Thanks :D Really appreciate it.
Still perfect after two years. Great work! The best method I've ever seen about deploying the app to EC2.
Thanks mate!
this has been quite a journey, thank you so much!
This is by far the best tutorial on Django deployment and the best on Docker. Great explanation on every detail. Thanks so much Mark!
Glad it was helpful!
Been trying to find this!! thank you again Mark, you never cease to amaze me and be on the right time ahaahaha
That's fantastic, thank you :D
Great video Mark, keep up the good work! I like the way you slowly explain what you do with no extra unnecessary "decorative" remarks. Hope to have a pint of beer with you sometime in London mate!
I am so thankful for your video Mark. You are an excellent, EXCELLENT teacher. One of the best tutorials for CS on UA-cam for any subject! Keep up the wonderful work and I will be praying for your channel to grow even more!
The best tutorial and instructor I've seen on the subject. really amazing
Thank you!
Hey Mark, really appreciate for your tutorial. This is the exactly video I was looking! It was so detailed and you explain everything so well. Thank you!❤
You're welcome. Thanks for watching and I'm happy you found it useful.
Following along this video allowed me to host my first ever webpage! Thank you lots!
So glad to hear this! Well done.
Hey Mark, in my opinion one of the best tutorials on youtube. Thank u very much for your detailed explaination. This helped me a lot for our university project. kind greetings from germany
This is exactly what I have been looking for. I took your "Rest API" course on Udemy and learned a lot. Thanks again.
Uploaded at the right time. You're a Legend!
Thank you! Glad it is useful.
Increadibly proffessional. Blog and the video itself. I am amazed. Thank you so much.
Thanks for your kind words. Glad you found it useful!
Ultimate explanation and the integration. Thanks for such excellent presentation and work.
Thanks for taking out time to create this tutorial. This video sooo good that I had to purchase the advanced course.
this is a great video. so much useful stuff in it that it taken 5 sittings to complete and over a month
just about completed this now :)
Most recent working versions are:
Dockerfile: python:3.11-alpine3.15
docker-compose.yml / docker-compose-deploy.yml
- Python 3.11
- Image: postgres:15-alpine
Requirements.txt:
Django==4.2
psycopg2==2.9.6
uWSGI==2.0.21
Yo Mark! I purchased your advanced Django course on Udemy a couple of years ago and it's the best damn course on the subject. Perhaps the only thing missing was how to deploy the project to AWS using Docker containers, so thanks for this video! Keep up the good work, my dude.
Hey Antonio, thanks so much, really appreciate that. I'll keep your feedback in mind and hope to create content on it soon!
@@LondonAppDeveloper can i have the link to your udemy course?
very well explained the part of wsgi, nginx, static files . Very good
Thanks so much!
Thanks a lot. What i was waiting for
Great! Let me know what you think.
@@LondonAppDeveloper thanks a lot in advance for this video. I have a complete django project to deploy with a e-commerce, models, and many IOt features . I have tried in many time to deploy but didn't work or worked only launching a runserver into a instance now i am following your tutorial to see whether it works on aws . Thanks for your interesting videos. All the best regards
Awesome tutorial. So many concepts clarified
This tutorial is amazing, thank you for the content!
Can't figure out where to put css and js files... I know it has something to do with vol/web/static but I'm pretty stuck...
Did you find any way?
I’ve mashed the subscribe and like buttons! An excellent tutorial - I’ve been wondering about this topic for a while. I’ve learnt an enormous amount. If I get stuck with it I’ll either be doing the full course or contacting you direct for some consulting. Great work, thank you 👍
i never write youtube comments but this tutorial was amazing. thank you
Thanks mate so happy to hear that.
@@LondonAppDeveloper im trying to connect my react app to my EC2 instance but it fails to connect over HTTPS. It works perfectly fine over HTTP. Have been looking for solutions but failed miserably. Im not sure if the docker setup is the issue or not. Any recommendations on where to look?
Thanks for the excellent tutorial Mark. successfully tested the deployment on the production server locally but, have some problem in the development, particularly in the " MEDIA_ROOT='/vol/static/media' ", it gives me Permission denied error and was not mounted on the "/data/web", but when using " MEDIA_ROOT='vol/static/media/' ", there is no error and can saved the media in "app/app/vol/static/media" and was not mounted in "/data/web/". anyway, the production deployment was great locally, haven't tested it yet in the actual production server, thanks Mark. keep it up.
same problem here
@@nicolasqueiroga6455 maybe is this: When docker create a data/web to our system it creates with user roots permissions, so when Django app tries to save the file can't. so just change the permissions data/web file to your current user.
I'm trying to deploy this to Heroku and I am stuck on this - Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
I know I'm supposed to get the port it's served on using an ENV variable that Heroku randomly assigns it, but my understanding of Nginx and docker isn't sufficient enough for me to figure out where to change what. Does anyone have experience with this?
thank You very much for the class but I ran into a problem when running docker-compose build and here is response i got
Error while fetching server API version: (2, 'CreateFile', 'The system cannot find the file specified.')
[9676] Failed to execute script docker-compose
Thank you so much for such a wonderful explanation. Best tutorial
Great tutorial thanks.
I have a few questions/Notes.
1. If you use -volumes: ./app:/app Why do you create a directory 'app' and then name your project 'app' and put it inside 'app' directory ? It is so confusing.
2. where is /py/bin/ directory? inside docker container. It is the default in the 3.9-alphine3.14 image?
3. I'm using pipenv and do not understand about the PATH env variable. for what you need to change PATH = ...
4. 59:52 need to add ALLOWED_HOSTS = ["0.0.0.0"]
5. 1:14:10 PermissionError: [Errno 13] Permission denied: '/vol/web/media' . Answer: need to have permissons on all your local files.
2:00:00
db_1 | Error: Database is uninitialized and superuser password is not specified.
app_1 | Database unavailable, wait 1 second...
I'm stuck
on this mistake
ERROR: unable to select packages:
postgresql-clien (no such package):
required by: world[postgresql-clien]
ERROR: Service 'app' failed to build :
I was trying to use pipenv
RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
/py/bin/pip install pipenv && \
apk add --update --no-cache postgresql-clien && \
apk add --update --no-cache --virtual .tmp-deps \
build-base postgresql-dev musl-dev linux-headers && \
pipenv shell && \
apk del .tmp-deps && \
adduser --disabled-password --no-create-home app && \
mkdir -p /vol/web/static && \
mkdir -p /vol/web/media && \
chown -R app:app /vol && \
chmod -R 755 /vol && \
chmod -R +x /scripts
if occurs problems with pipenv and psql
pipenv install psycopg2-binary
After 2 weeks tryings I think I will try to deploy on DigatalOcean. Because I think for new one it is hard.
postgresql-client, not clien
@Pelin Mutanguha Yes I am getting also same error, if you got any solutions please post here.
Hey, for the permissions error, what do you mean by "need to have permissons on all your local files. ". It would be nice if you could offer specific steps on how to achieve that.
If anyone is facing the PermissionError: [Errno 13] Permission denied: '/vol/web/media' issue, here's the fix:-
TLDR fix - enter this command in the terminal from inside the root folder - "sudo chmod -R a+rwx ./data"
Explanation - So, in the docker-compose.yml, because we added ./data/web:/vol/web, under volumes, when we upload a file, it uses the same app user specified in the Dockerfile to write the uploaded file to the ./data folder. So making the /data folder writable fixes the issue
@@humanzeeing Thanks Raga! That helped me a lot.
Thanks for this wonderful tutorial. I took your course on Django API using docker Udemy, lovely course, but it could use an update. Thanks once again
How do you apply for that course brother
How do you apply for that course brother
Thank you for the detailed tutorial :) it helped!
I LOVED IT YOU SAVED ME A WEEK
This is what I'm talking about ! Thank you sir !
Thanks
Hey Devon, thanks so much, really appreciate the super thanks! :D
Hi. Why do we need volume 'static-data' in app container (django app) when all of the media requests are served through NGINX? Thanks
could you help to make an example how to add SSL certs to nginx django uwsgi deploy with docker. thankyou so much
Totally fantastic video!!! Lot of thanks!
Will there be any need for the wait_for_db command if postgresql is defined before the app service? I don't really know docker but from the outputs it seems to run from top to bottom.
This was very helpful!
brilliant tutorial. thank you for this video
This is a great tutorial, so I definitely liked and subscribed. I'm not a fan of the deployment method (github actions would be nicer), but the way you configured docker for local django development and introducing env variables seems to be the best way I've seen, and I think the nginx container handling static is has its advantages over S3 for smaller sites. But that's the beauty of tutorials, you don't have to adopt everything exactly the same.
I do have a couple of questions more down to Django development though:
What I envision with Django for CMS kind of sites is that I want to develop a starting point with my core app locally, but have it so my pages (like "about" and "contact us" kind of pages) are built out without hard coding content, so I'd have a model in the core app called Page. The problem this introduces though is that a database migration won't populate the content from dev to prod. So I'd need a deployment step that backs up the local db and restores it to the prod db.
Is this an approach you'd take, or would you try to leave database stored content as something that shouldn't be in each environment?
My other question is down to the wait_for_db command. Is there a reason this is in an app rather than the actual project folder where the settings.py file is located?
Brilliant tutorial! Thank you!
I am stuck making migrations. I have a Mac and use PostgreSQL. I want to use my local machine database, not a Docker image. I cannot connect to that DB. Any help?
Thank you for great tutorial!!
You're welcome, thank you for watching!
absolutely fantastic!! and I'm only at minute 43 !!!! gooooo
Now, How can we set ssl certificate to that
Tnx man for this amazing tutorial
How can I solve this error? After giving permission to the vol why its giving error?
PermissionError: [Errno 13] Permission denied: '/vol/web/media'.
I have followed your video as well as blog.
I'm having the same issue. :(
If anyone is facing the PermissionError: [Errno 13] Permission denied: '/vol/web/media' issue, here's the fix:-
TLDR fix - enter this command in the terminal from inside the root folder - "sudo chmod -R a+rwx ./data"
Explanation - So, in the docker-compose.yml, because we added ./data/web:/vol/web, under volumes, when we upload a file, it uses the same app user specified in the Dockerfile to write the uploaded file to the ./data folder. So making the /data folder writable fixes the issue
Very good tutorial! Hope you still take questions. I have only one issue confusing me and this relates to line 23 of the Dockerfile - the app:app. I assume the 2nd app is the added user. What does the first app refer to?
why do need to build postgres-client? i just put the pyscog-binary in requirements.txt?
psycopg2-binrary is not recommended for production as mentioned on their pip page: pypi.org/project/psycopg2-binary/ "The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources.".
If you need to install it directly for dev only then it's fine, but my philosophy is to use Docker to match both local dev/prod as closely as possible.
Awesome tutorial, I've watched it till the end and everything worked.
But when I came back to this project after a week and tried to launch it didn't connect me to the website and throw err_connection_timed_out error in browser.
I've checked and replaced host address with new one which was provided by ec2 (after relaunching instance). What could be wrong?
Hey mate, could be that the ALLOWED_HOSTS needs to be changed? I didn't think it would re-assign a hostname after re-launch though.
@@LondonAppDeveloper Thanks for the answer but I've already changed the ALLOWED_HOSTS variable via "vi .env", moreover I tried to use Elastic IP adress to keep IP adress during sessions but that didn't work. I've also tried to create another instance and deploy project there but still the same result... After a while there were some queries in the console but all of them were with "HTTP 400" and they weren't connected with my attempts to reach the website. I've spent a day and a half to find information but there was none.
@@robertkhakimov3262 any updates?
I stuck on the same one. Locally, project is working. Bu on ES2 not.
@@RuslanSkiraUkraine , I've solved it in a bit odd way. So when you open your ec2 instance in browser you can see the Public IPv4 address and Public IPv4 DNS with buttons "open address". I've always tried to open my website via these buttons but never succeeded (err_connection_timed_out). But then I just copied and pasted IPv4 and all of a sudden everything worked as usual. I think it's because when you press the button it opens website using https protocol but if you copy and paste the actual ip it will be opened with http. Hope this helps.
@@robertkhakimov3262 Thank you for the fast response. I was trying it. It doesn't help me.
Best tutorial I have seen about django +. container + deployment. Really appreciated. I deployed an app using it. maybe could be interesteing to explaing it using asgi instaed of wsgi, for example in my app I'm using django channels to use websockets and I had to use asgi, how we can deploy that to production. thanks
db_1 | 2022-01-20 10:09:47.641 UTC [67] DETAIL: Password does not match for user "approotuser".
db_1 | Connection matched pg_hba.conf line 99: "host all all all md5"
db_1 | 2022-01-20 10:09:48.645 UTC [68] FATAL: password authentication failed for user "approotuser"
db_1 | 2022-01-20 10:09:48.645 UTC [68] DETAIL: Password does not match for user "
I got the same issue i think docker-compose can't read .env file but i don't know how to fixed it.
Hello London App developer, I have an issue whenever I run the command "docker-compose -f docker-compose-deploy.yml up" I run into th django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please suppl
y the NAME or OPTIONS['service'] value." Any help rendered I will be so appreciative
Thank you for such a nice video.
i am getting an error PermissionError: [Errno 13] Permission denied: '/vol/web/static/admin'
when doing collect static please help
How can I add cron jobs in this docker? before docker I used Django-crontab
One of the best Video....
Great tutorial. Thanks for sharing.
Hello! You didn’t tell how to resolve the issue of Not found, that happened almost in the end of video. please let me know that how to do port mapping in docker-compose-deploy.yml, only admin endpoint is working. i want to extend this website by adding more different thing. please reply and help me with it
Amazing tutorial!
Can you tell about how to handle the "502 Bad Gateway nginx" error. server runs on a digital ocean droplet. I tried to access the server via droplets public ip
I had to set the owner of the /data to the UUID of the docker user during debugging manually to proceed. Did I skip a crucial step?
Hmm weird... Are you using Linux? Or running Docker using sudo?
@@LondonAppDeveloper yes, I am on Linux. Forgot to mention that my apologies
can you please help me to fix this issue :-
PermissionError at /admin/core/sample/add/
[Errno 13] Permission denied: '/vol/web/media'
Thanks man this was really nice👍
Glad it helped.
This tutorial is awesome,
Thanks so much!
Thank you thank you thank you !!!!! This has been great fun ! Had some trouble with the MEDIA_ROOT needing to be 'vol...' and not '/vol...' but aside from that smooth sailing :) Now I can make my best friend a webapp for Xmas !!
Great to hear! Hope your friend enjoys their Christmas web app.
For some reason, the wait_for_db command is stuck in a loop even after postgres is available
HI + SOS,
i'm watching+learning this video in year 2024. I wonder if the workflow has change since then.
Hi Mark! Please let me know how to do port mapping in order to scale up this website. You just worked on admin url, anything other url doesn’t work. It say thay “Not found”.
If anyone is facing the PermissionError: [Errno 13] Permission denied: '/vol/web/media' issue, here's the fix:-
TLDR fix - enter this command in the terminal from inside the root folder - "sudo chmod -R a+rwx ./data"
Explanation - So, in the docker-compose.yml, because we added ./data/web:/vol/web, under volumes, when we upload a file, it uses the same app user specified in the Dockerfile to write the uploaded file to the ./data folder. So making the /data folder writable fixes the issue
Thx
"sudo chmod -R a+rwx ./data" alone didn´t fix the issue in my case. I also had to change the ownership from ROOT to MY_USER by executing "sudo chown -R MY_USER:MY_USER ./data". Only then it worked!
How can i access to the root folder from the terminal?
@@humbertocueva3815 just cd into the path where your project exists. Once you are inside the project folder that's what is called the root folder. Basically which ever folder the .data folder exists.
If you're a newbie, then just open the project folder in vscode and select new terminal from the top menu and it will launch the terminal directly in the root folder of the project. From there you can directly enter the command. If it doesn't work just type ls -al and make sure that the .data folder exists within the folder you're in.
I'm a pretty late, but I wanted to add to this to help future people figure out this problem for themselves. I'm using bash, and for me personally, only changing ownership was necessary . When django automatically creates the ./data/web/ path, the permission types for these directories were the same as all the other directories in the project folder, which for me is 755 (that's rwxr-xr-x for those unacquainted). You can check by "typing ls -al" from the project's root directory. The real problem is that the /data/web directories are given "root" permissions instead of user permissions (if so, it will be indicated by "root root" in the list instead of "[user] [user]" like eveything else.
So I believe simply starting from the root folder and running "sudo chown -R [user]:[user] data/" (and only this) like in Oliver's post would be all that's necessary for most people, unless they have more restrictive permission types set up for their project directory. If the latter is the case, subsequently running "sudo chmod -R 775 /data" from the project's root directory will suffice.
If security isn't a concern, you can just use Ragav Y's version of the chmod command in the original message to nuke it from orbit. I just wanted to add that the core issue is likely the owner of the directories, not the permission types, but your mileage may vary.
how do you update the migrations in the db?
Hey London App Developer. one day i will meet you in London
Yeah that would be cool! I'm living on Isle of Dogs right now :D
Great tutorial.
Could you point me how to enable SSL using this setup with Ngix?
Great question. I'm going to make another tutorial about SSL. The way to do it is like this:
1) Procure SSL certificates,
2) Update NGINX config to add SSL support,
3) Update the Docker Compose config and security groups to allow access via port 443,
4) Add a volume to the NGINX service which maps the server directory containing the SSL certs to the directory NGINX is configured to find them.
It would also be possible to use Let's encrypt by adding another service to the deployment docker compose which runs the agent that updates the certs. I expect this would involve mapping a volume for the certs and a volume for the refresh keys that I believe needs to be served via NGINX. I need to spend some time figuring it out myself before I create a guide on it :)
@@LondonAppDeveloper Thank you so much for taking the time to answer. I will give the first option a try. You have no idea how much value you are offering to the community!
hi were you be able to add ssl to this setup? and how you did it if yes?
this is a gem
Thanks a lot for this, going to watch through it all and follow along this weekend
Thanks just suscribed!. Do you always lose the data in database when deploying? how can I make it so that i dont. Just starting and i will like to dockerize a project that is already deployed.
thanks. can you please do ssl par?
Hi Mark. Excellent videos tutorial. I tried following every step in your video but unfortunately i met error when i run command : docker-compose run --rm app sh -c "django-admin startproject app ." sh: django-admin: not found (Error : 127) I stop the tutorial since i have this issue. Please advise. Thank you.
Great video !
Hello Mark, thank you for this great course it is short and precise. I would like to request if you have a specific course on handling static files. I will greatly appreciate it.
Would you please do all this again but using latest version of Django 4. Thanks
The steps are pretty much the same whether you do it with Django 4 or 5 now. The focus of this video is the Docker part.
Thanks a lot for the lessons! you have the best content! I have a question, did we write the “migrate” command in the script, and in the case of development, do we have to execute the “makemigrations” command manually? Or can this one be automated as well? for example to register in “Dickerfile”?
Why not using elastic beanstalk ?
really helpful thank you!
You're welcome!
This would be even more enlighting when having a Frontend (react etc), Backend (django), DB (Postgres etc) and Proxy (Nginx).
If I remember correctly, there is a video about setting this all up (except Frontend) in this channel.
ua-cam.com/channels/3RtgbslbAvE-5FFBkSgpig.html I second that. Perhaps Angular frontend that uses the same docker-compose to make it more interesting.
@@sariyanta This is that exact video. The other guy wanted mainly a frontend in addition to the other stuff already taught in this video.
can you add a postgresql database service to the docker-compose.debug.yml that VS Code generates?
When I run the command ‘’’ docker-compose -f docker-compose-deploy.yml down - -volumes ‘’’ I run into errors that the specified file is not found. And when I run “ls” the file isn’t displayed
What could be the problem
@@isaackmata7235 do you have a file named docker-compose-deploy.yml ?
@@tonyleotta6715 yes I do have the file “””docker-compose-deploy.yml”””
Excellent ! Thanks a lot !
No worries, glad it was useful.
I am having trouble doing the docker compose build, because I have pandas on the requirements, do you happen to know how to solve it? I have been trying to solve it for the whole week and I can't find any solutions. Thank you!
Can I do all the configuration above and run on AWS Lightsail??
Not used Lightsail myself but I think it's just like Digital Ocean (you buy a VM and get access to it?)... Answer is probably yes, but of course some of the steps will be different. Not sure if Lightsail gives the option to use the Amazon Linux 2 AMI? The project setup and deployment part should work the same.
@@LondonAppDeveloper will try it out... Thank You!!!
Hello! Does DRF deployment have the same steps as this one?
Yes
how to add SSL certificate
Hi, very nice tutorial indeed. I have question regarding applying SSL Certificate on Nginx and expose to port 443. Do you have any working example?
Why shouldn't we use "sudo useradd app" instead of "adduser --disabled-password --no-create-home app"? First command wouldn't create home directory and password by default
Brother I have an issue
Can you help me out please
Whenever I run the command “ docker-compose -f docker-compose-deploy.yml” I run into errors that settings.DATABASES is improperly configured
@@isaackmata7235 Not enough details, I need to see your project. Do you have discord account or telegram?
Hi, first of all thank you for this great video! Second, I have a question regarding named volumes. static-data volume is populated by the app service, then this volume is used by the proxy service. Is the volume sourced by the app service and not by the proxy because the proxy depends on the app?
The volume is not necessarily sourced by either container. The volume is the volume, and it's shared with the two containers that need the data. Apologies if I misunderstood the question.