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.
├── pyproject.toml
└── docker
└── Dockerfile
└── docker-compose.yml
└── mysite/*
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"
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
The point is to set the parameter to runserver 0.0.0.0:8000
This will also stop the breakpoint. The file will be modified and reflected without restarting docker-compose.
This makes the host side clean. You can easily build a development environment.