Build a development environment with Poetry Django Docker Pycharm

Introduction

It's been a year since I started python, but I'm still not used to building a Python environment. Package managers in particular feel like the weakest of many languages. For some reason, when I tried to build a development environment on mac, an error related to OpenSSL occurred.

We have summarized how to build a development environment on docker to solve such problems.

The source is listed on Github.

Directory structure

├── pyproject.toml
└── docker
    └── Dockerfile
    └── docker-compose.yml
└── mysite/*

File

Only the main files are described. Keep the files created by Django.

pyproject.toml


[tool.poetry]
name = "python-dev-on-docker"
version = "0.1.0"
description = ""
authors = ["va034600"]

[tool.poetry.dependencies]
python = "^3.6"
django = "^3.1.1"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

Dockerfile


FROM python:3.6.8
WORKDIR /usr/src/app

ENV POETRY_VERSION=1.0.10 \
    PATH="/root/.poetry/bin:$PATH"
RUN curl -sSL https://raw.githubusercontent.com/sdispater/poetry/${POETRY_VERSION}/get-poetry.py | python && \
    poetry config virtualenvs.create false
COPY ./pyproject.toml /usr/src/app/pyproject.toml
RUN poetry install

CMD tail -f /dev/null

docker-compose.yml


version: '3.5'
services:
  app:
    build:
      context: ../
      dockerfile: ./docker/Dockerfile
    working_dir: /usr/src/app/mysite
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - ../mysite:/usr/src/app/mysite
    ports:
      - "8000:8000"

Run docker-compose from console

For the time being, check the operation with docker-compose up without Pycharm.

$ cd docker
$ docker-compose up -d
$ curl http://127.0.0.1:8000/
$ docker-compose down
hello1

Debug with Pycharm

Pycharm settings

Add Python Interpreter with docker-compose

スクリーンショット 2020-09-13 9.41.41.png

Set the project Interpreter to docker-compose

Preferences.png

Create a runserver in Configuration

The point is to set the parameter to runserver 0.0.0.0:8000 Run_Debug_Configurations.png

Debug with Pycharm

This will also stop the breakpoint. The file will be modified and reflected without restarting docker-compose.

At the end

This makes the host side clean. You can easily build a development environment.

Recommended Posts

Build a development environment with Poetry Django Docker Pycharm
[Django] Build a Django container (Docker) development environment quickly with PyCharm
[Python] Build a Django development environment with Docker
Build a Django development environment with Docker! (Docker-compose / Django / postgreSQL / nginx)
[Memo] Build a development environment for Django + Nuxt.js with Docker
Build a Django development environment with Doker Toolbox
I made a development environment for Django 3.0 with Docker, Docker-compose, Poetry
[DynamoDB] [Docker] Build a development environment for DynamoDB and Django with docker-compose
Create a Todo app with Django ① Build an environment with Docker
Easily build a development environment with Laragon
[Linux] Build a jenkins environment with Docker
[Linux] Build a Docker environment with Amazon Linux 2
Build a C language development environment with a container
Build the fastest Django development environment with docker-compose
Go (Echo) Go Modules × Build development environment with Docker
Build a Django environment with Vagrant in 5 minutes
Quickly build a Python Django environment with IntelliJ
Get a quick Python development environment with Poetry
Build a Django development environment using pyenv-virtualenv on Mac
How to build a Django (python) environment on docker
Build a machine learning application development environment with Python
Build a Django environment for Win10 (with virtual space)
Build a lightweight Fast API development environment using Docker
Build a local development environment with WSL + Docker Desktop for Windows + docker-lambda + Python
Build a go environment using Docker
Build Mysql + Python environment with docker
Deploy a Django application with Docker
Build PyPy execution environment with Docker
Build a web application with Django
Rebuild Django's development environment with Docker! !! !! !!
Build a Go development environment with VS Code's Remote Containers
Build a comfortable development environment with VSCode x Remote Development x Pipenv
How to build a python2.7 series development environment with Vagrant
Create a simple Python development environment with VSCode & Docker Desktop
Build a Flask development environment at low cost using Docker
[Django] Use VS Code + Remote Containers to quickly build a Django container (Docker) development environment.
Build Jupyter Lab (Python) environment with Docker
Build a Tensorflow environment with Raspberry Pi [2020]
Build a Python environment on your Mac with Anaconda and PyCharm
Build a Fast API environment with docker-compose
Create a development environment for Go + MySQL + nginx with Docker (docker-compose)
Build a python virtual environment with pyenv
Create a simple Python development environment with VS Code and Docker
Build a modern Python environment with Neovim
Build NGINX + NGINX Unit + MySQL environment with Docker
Learning history to participate in team application development with Python ~ Build Docker / Django / Nginx / MariaDB environment ~
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Easy construction]
Build a CentOS Linux 8 environment with Docker and start Apache HTTP Server
I tried to build a Mac Python development environment with pythonz + direnv
Steps to build a Django environment with Win10 WSL Ubuntu18.04 + Anaconda + Apache2
Build a LAMP environment on your local Docker
Build a WardPress environment on AWS with pulumi
Build Python development environment with Visual Studio Code
Build a Django environment on Raspberry Pi (MySQL)
Build a python environment with ansible on centos6
Building a Python environment with WLS2 + Anaconda + PyCharm
Start Django in a virtual environment with Pipenv
Create a python3 build environment with Sublime Text3
Create Nginx + uWSGI + Python (Django) environment with docker
Build a Python development environment on your Mac
[Memo] Build a virtual environment with Pyenv + anaconda