Docker containment


 To make it easier to deploy on a live server and develop on a different environment we'll dockerize our projects. If you are not familiar with Docker you best read up on it here. But to simplify Docker allow us to run everything in a virtual environment so there no complication caused running on different systems.

We'll need to add a couple of files for this. starting with a requirment.txt, This file will contain all the added dependencies for python. Currently we're only adding Django but if we later use more we just simply add it here and Docker will install all of them with PIP.

Our file looks like this:

Django==3.0.7

Now it time to make the Dockerfile that will setup our environment. This will setup up the working directory and install the dependencies listed in requirment.txt and looks like this:

# pull official base image
FROM python:3.8.3-alpine

# set work directory
WORKDIR /usr/src/app

# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt

# copy project
COPY . .

Last is the docker-compose.yml file. This will setup all our docker images. This is only our web for now.

version"3.7"

services:
  web:
    build.
    commandpython manage.py runserver 0.0.0.0:8000
    volumes:
      - ./:/usr/src/app/
    ports:
      - 8000:8000
    env_file:
      - ./.env.dev

There we go, we've Dockerized our project, to run it with docker run these two command.

  • docker-compose build
  • docker-compose up -d

If anything went wrong you can't find it in the log with

  • docker-compose logs -f

Comments

Popular posts from this blog

Blender api script

Nasa topographic data

Project concept