Create a simple Python development environment with VS Code and Docker

Introduction

When developing with Python running on Docker with VS Code, create a simple development environment that will complete the code properly.

Preparation

Install VS Code Docker and Romete-Containers extensions スクリーンショット 2020-12-21 0.34.01.pngスクリーンショット2020-12-210.38.52.png

Build Python 3 environment with Docker

For the Python environment construction itself, I referred to Try to create a Python3 environment easily with docker.

├ Dockerfile
├ docker-compose.yml
└ workspace/ (Mount this on a container and develop)

Dockerfile


FROM python:3

RUN apt-get update
RUN apt-get -y install locales && \
    localedef -f UTF-8 -i ja_JP ja_JP.UTF-8
ENV LANG ja_JP.UTF-8
ENV LANGUAGE ja_JP:ja
ENV LC_ALL ja_JP.UTF-8
ENV TZ JST-9
ENV TERM xterm

RUN pip install --upgrade pip
RUN pip install --upgrade setuptools

Mount workspace on the container. (To inherit the edited contents in the container)

dokcer-compose.yml


version: '3'
services:
  python3:
    restart: always
    build: .
    container_name: 'python3'
    working_dir: '/workspace/'
    tty: true
    volumes:
      - ./workspace:/workspace

Start container

$ docker-compose up -d --build

Verification

$ docker ps
CONTAINER ID        IMAGE                COMMAND             CREATED             STATUS              PORTS               NAMES
ab664cabca5f        python-dev_python3   "python3"           44 minutes ago      Up 44 minutes                           python3

Install the required libraries (install numpy properly to check code completion)

pip install numpy

Connect to the started container with VS Code

If you specify a container from Docker in the sidebar and select Attach Visual Studio Code, a new VS Code window connected to the container will open. スクリーンショット 2020-12-21 0.43.53.pngスクリーンショット2020-12-210.08.30.png Select "Open Folder" and select the mounted directory. スクリーンショット 2020-12-21 0.13.56.png To use a Python extension in a container, install the Python extension in the container. スクリーンショット 2020-12-21 0.16.36.png Create a suitable Python file and specify Python running on Docker as the interpreter. This time Python 3.9.1 スクリーンショット 2020-12-21 0.27.53.png This will complement it properly when using the library installed in the container. スクリーンショット 2020-12-21 0.27.03.png

reference

Try to create a python3 environment easily with docker

Recommended Posts

Create a simple Python development environment with VS Code and Docker
Create a simple Python development environment with VSCode & Docker Desktop
Create a VS Code + Docker development environment on a Linux VM
Build a development environment using Jupyter and Flask with Python in Docker (supports both VS Code / code-server)
Create a C ++ and Python execution environment with WSL2 + Docker + VSCode
[Python] Build a Django development environment with Docker
Build a python execution environment with VS Code
Steps to create a Python virtual environment with VS Code on Windows
Create a python development environment with vagrant + ansible + fabric
Create a virtual environment with Python!
Cross-compiling Raspberry Pi and building a remote debugging development environment with VS Code
Set up a Python development environment with Visual Studio Code
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
[Python] Create a virtual environment with Anaconda
Create Python + uWSGI + Nginx environment with Docker
Create a Python environment for professionals in VS Code on Windows
Try to create a python environment with Visual Studio Code & WSL
Create a development environment for Go + MySQL + nginx with Docker (docker-compose)
How to build Python and Jupyter execution environment with VS Code
[DynamoDB] [Docker] Build a development environment for DynamoDB and Django with docker-compose
[No venv required] The strongest Python development environment created with Remote Containers [VS Code / Docker]
Create a simple Python development environment with VS Code and Docker
Blender 2.82 or later + python development environment notes
Building a python environment with virtualenv and direnv
Python (Windows 10) Virtual Environment / Package with VS Code
Create a virtual environment with conda in Python
Create a python3 build environment with Sublime Text3
Create Nginx + uWSGI + Python (Django) environment with docker
Use Python in Anaconda environment with VS Code
Build PyPy and Python execution environment with Docker
[Docker] Create a jupyterLab (python) environment in 3 minutes!
Create a Python virtual development environment on Windows
Make your Python environment "easy" with VS Code
Get a quick Python development environment with Poetry
Prepare a Python virtual environment for your project with venv with VS Code
[AWS] Create a Python Lambda environment with CodeStar and do Hello World
Create a Python development environment on Windows (Visual Studio Code remote WSL).
Create a Python (Django) learning environment with Docker so that you can debug with VS Code (almost your own procedure memo)
Create a Python development environment in 10 minutes (Mac OS X + Visual Studio Code)
Put Docker in Windows Home and run a simple web server with Python
Python with VS Code (Windows 10)
How to debug a Python program by remotely connecting to a Docker container in WSL2 environment with VS Code
Building a Docker working environment for R and Python
Build a python virtual environment with virtualenv and virtualenvwrapper
Allow real-time code checking in Python development with VS Code
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Trial and error]
Create a simple reception system with the Python serverless framework Chalice and Twilio
Create a comfortable Python 3 (Anaconda) development environment on windows
Let's make a simple game with Python 3 and iPhone
Debug Python with VS Code
Prepare python3 environment with Docker
Build a machine learning application development environment with Python
Build a python virtual environment with virtualenv and virtualenvwrapper
Python development environment with Windows + Anaconda3 + Visual Studio Code
Create a Layer for AWS Lambda Python with Docker
Easy Python data analysis environment construction with Windows10 Pro x VS Code x Docker
Manage Python runtime packages and development environment packages with Poetry
Python development environment with Windows + Python + PipEnv + Visual Studio Code
Create a directory with python
Create a decent shell and python environment on Windows
Build a development environment with Poetry Django Docker Pycharm
Build a local development environment with WSL + Docker Desktop for Windows + docker-lambda + Python