This quickstart assumes OS X 10.13, PyCharm 2018.1, Docker 18.03, and Python 3.7.
- Start Docker and PyCharm
- Create new project - "Pure Python"
- Set project name and temporarily set the project interpreter to Existing interpreter > Python 3.x (local)
- Create
Dockerfile
and/ordocker-compose.yml
(see samples of each below), and optionally an "output" folder. - Now reset the project interpreter to Docker by going to Preferences >
Project Interpreter > [Cog wheel] Add... and choose Docker Compose.
- You may need to "Run" the docoker-compose.yml file in order to create the containers initially. I'm not 100% - I was having some Docker/PyCharm challenges when writing this...
Now when you run a .py
file it will execute in the Docker container, not the
local interpreter.
This will start a Python 3 container with a /code/
directory in it. It will
then copy and install your requirements, and then copy in your code.
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
## Uncomment if using requirements.txt
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
This will build a container called "app" based on the Dockerfile
above and
mirror the local "output" folder to /code/output/
.
version: '3'
services:
app:
build: .
volumes:
- ./output/:/code/output/
# Debug
tty: true
stdin_open: true