STEP1: install docker and docker compose
1. sudo apt-get install docker-ce docker-ce-cli containerd.io
2. sudo groupadd docker
3. ubuntu@ubuntu2004:~$ sudo usermod -aG docker $USER (you should be able to run docker with user ubuntu now)
4. sudo curl -L “https://github.com/docker/compose/releases/download/1.28.5/docker-compose-$(uname -s)-$(uname -m)” -o /usr/local/bin/docker-compose
5. sudo chmod +x /usr/local/bin/docker-compose
STEP2: create Django_Compose folder and files:
Dockerfile
requirements.txt
docker-compose.yml
ubuntu@ubuntu2004:~/Django_Compose$ cat Dockerfile FROM python:3 ENV PYTHONUNBUFFERED=1 WORKDIR /code COPY requirements.txt /code/ RUN pip install -r requirements.txt COPY . /code/ ubuntu@ubuntu2004:~/Django_Compose$ cat requirements.txt Django>=3.0,<4.0 psycopg2-binary>=2.8 ubuntu@ubuntu2004:~/Django_Compose$ cat docker-compose.yml version: "3.9" services: db: image: postgres environment: - POSTGRES_DB=postgres - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres web: build: . command: python manage.py runserver 0.0.0.0:8000 volumes: - .:/code ports: - "8000:8000" depends_on: - db
STEP3: Create a Django project
sudo docker-compose run web django-admin startproject composeexample .
sudo chown -R $USER:$USER .
STEP4: edit composeexample/settings.py
Replace the DATABASES = … with the following:
and also update ALLOWED_HOSTS = [‘*’]
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'postgres', 'USER': 'postgres', 'PASSWORD': 'postgres', 'HOST': 'db', 'PORT': 5432, } }
STEP5 : start docker compose with command “docker-compose up”
ubuntu@ubuntu2004:~/Django_Compose$ docker-compose up Starting django_compose_db_1 ... done Starting django_compose_web_1 ... done Attaching to django_compose_db_1, django_compose_web_1 db_1 | db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization db_1 | db_1 | 2021-03-11 17:34:58.762 UTC [1] LOG: starting PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit db_1 | 2021-03-11 17:34:58.762 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 db_1 | 2021-03-11 17:34:58.763 UTC [1] LOG: listening on IPv6 address "::", port 5432 db_1 | 2021-03-11 17:34:58.765 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" db_1 | 2021-03-11 17:34:58.770 UTC [25] LOG: database system was shut down at 2021-03-11 17:25:27 UTC db_1 | 2021-03-11 17:34:58.775 UTC [1] LOG: database system is ready to accept connections web_1 | Watching for file changes with StatReloader web_1 | Performing system checks... web_1 | web_1 | System check identified no issues (0 silenced). web_1 | web_1 | You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. web_1 | Run 'python manage.py migrate' to apply them. web_1 | March 11, 2021 - 17:35:00 web_1 | Django version 3.1.7, using settings 'composeexample.settings' web_1 | Starting development server at http://0.0.0.0:8000/
I was suggested this website by my cousin. I’m not
sure whether this post is written by him as nobody else know such detailed
about my trouble. You’re amazing! Thanks!
Its like you read my thoughts! You seem to understand so much about
this, like you wrote the e-book in it or something. I feel that you just can do with some
p.c. to drive the message home a bit, but other than that,
that is magnificent blog. A fantastic read.
I’ll definitely be back.
I’m extremely impressed with your writing skills as well as with the layout on your weblog.
Is this a paid theme or did you customize it yourself?
Either way keep up the nice quality writing, it’s rare to see a nice blog like this one today.
Also visit my blog post – http://www.diigo.com
This post is truly a pleasant one it assists new web visitors, who are wishing
for blogging.
Here is my blog :: Astroscope Reviews
Howdy! I know this is kinda off topic but I’d figured I’d ask.
Would you be interested in trading links or maybe guest authoring a blog post or vice-versa?
My website goes over a lot of the same subjects as
yours and I think we could greatly benefit
from each other. If you are interested feel free to shoot me an e-mail.
I look forward to hearing from you! Awesome blog by the way!
My site: Pellamore Cream
Thanks for the sensible critique. Me & my neighbor were just preparing to do some research about this.
We got a grab a book from our local library but I think I learned
more from this post. I’m very glad to see such magnificent info being shared freely out
there.
Also visit my website; Lilian
I was recommended this blog through my cousin. I am no longer certain whether
this put up is written by him as nobody else
know such distinct about my difficulty. You are wonderful!
Thanks!
Here is my webpage :: Rhino Spark Pills
Would love to forever get updated outstanding web blog!
Here is my web page: Green Earth CBD Gummies Review
Great – I should definitely pronounce, impressed with your
website. I had no trouble navigating through all tabs as well as related information ended up being truly easy to do to access.
I recently found what I hoped for before you know it at
all. Reasonably unusual. Is likely to appreciate it for those who add forums or something,
website theme . a tones way for your client to
communicate. Nice task.
My page :: http://librarius.main.jp
hello!,I really like your writing so a lot!
share we keep up a correspondence extra about your post on AOL?
I require a specialist on this space to resolve my problem.
Maybe that’s you! Having a look forward to see you.
My website; Alpha Extracts
Way cool! Some extremely valid points! I appreciate you writing this write-up and also the rest of the site is really good.
Here is my web-site Nature Fused Cream Reviews
I really like your writing style, great information, appreciate it for putting up :
D.
Take a look at my webpage; Strawberry CBD Gummies Review