# Topic covered
Docker-Compose
- DC makes it easier to configure and run applications made up of
multiple containers - DC is a very handy tool to quickly get docker environment up and running.
- It
uses yamlfiles to store the configuration of all the containers
We can create some containers like: web app, postgres and redis
and can establish an internal connection
Installation
sudo apt-get install docker-compose
# Check
docker-compose --version
docker-compose -v
V1 vs V2
# Old style (Compose V1)
docker-compose up
# New style (Compose V2).
docker compose up
Commands
# This will not build the image if it's already exists
docker-compose up
docker compose up -d
# Force to build the image
docker-compose build
docker-compose down
docker-compose config
# stops all the running containers without removing them.
docker compose stop
docker container stop <container id>
# removes all the containers.
docker compose rm
docker-compose up --build
Mini project - Mongodb and Node
DjRest-Adv
# Dockerfile
FROM python:3.7-alpine
MAINTAINER Hitman
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache postgresql-client jpeg-dev
RUN apk add --update --no-cache --virtual .tmp-build-deps \
gcc libc-dev linux-headers postgresql-dev musl-dev zlib zlib-dev
RUN pip install -r /requirements.txt
RUN apk del .tmp-build-deps
RUN mkdir /app
WORKDIR /app
COPY ./app /app
RUN mkdir -p /vol/web/media
RUN mkdir -p /vol/web/static
RUN adduser -D user
RUN chown -R user:user /vol/
RUN chmod -R 755 /vol/web
USER user
# docker-compose.yml
version: "3"
services:
app:
build:
context: .
ports:
- "8000:8000"
volumes:
- ./app:/app
command: >
sh -c "python manage.py wait_for_db &&
python manage.py migrate &&
python manage.py runserver 0.0.0.0:8000"
environment:
- DB_HOST=db
- DB_NAME=app
- DB_USER=postgres
- DB_PASS=supersecretpassword
depends_on:
- db
db:
image: postgres:10-alpine
environment:
- POSTGRES_DB=app
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=supersecretpassword
# django app inside app folder
# Run
docker-compose up