When developing with Python running on Docker with VS Code, create a simple development environment that will complete the code properly.
Install VS Code Docker and Romete-Containers extensions
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
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.
Select "Open Folder" and select the mounted directory.
To use a Python extension in a container, install the Python extension in the container.
Create a suitable Python file and specify Python running on Docker as the interpreter.
This time Python 3.9.1
This will complement it properly when using the library installed in the container.
Try to create a python3 environment easily with docker
Recommended Posts