Using venv in Windows + Docker environment [Python]

error

I get an error when I try to mount it in a container and use it in the usual way.

$ python -m venv .venv
Error: [Errno 71] Protocol error: 'lib' -> '/app/.venv/lib64'

Cause

Caused by issuing a symlink when using venv and sharing it when mounting locally

Solution

Use How to exclude some when mounting Volume with Docker to exclude it from the mount with the symbolic link.

In the command below, a symbolic link will be attached under ** {working directory} /. Venv / **, so exclude it.

python -m venv .venv

Part of docker-compose.yml

version: "3.7"
services:
  app:
    ...
    volumes:
      - {Working directory}/.venv/

docker-compose.yml

Whole sample

version: "3.7"
services:
  app:
    build: ./app/
    working_dir: /app
    volumes:
      - ./app:/app:cached
      - /app/__pycache__
      - /app/.venv/
      - /app/.tox/ #for tox
    environment:
        - FLASK_ENV=development
    ports:
    - "5000:5000"

reference

Recommended Posts

Using venv in Windows + Docker environment [Python]
python windows environment
Python environment construction procedure memo using Docker on Windows10 Home
Mouse operation using Windows API in Python
Python development environment for macOS using venv 2016
[FX] Hit oanda-API in Python using Docker
[Python] [Windows] Serial communication in Python using DLL
Building scikit-learn in Windows 10 environment using Pycharm
Python garbled in Windows + Git Bash environment
Build and try an OpenCV & Python environment in minutes using Docker
python windows environment construction
virtualenvwrapper in windows environment
virtual environment in python
Development environment in Python
Install Python 3.5.1 + numpy + scipy + α in Windows environment
Super easy! Python + Flask environment in Docker quickly
[Environment construction] Dependency analysis using CaboCha in Python 2.7
Use jupyter-lab installed in python virtual environment (venv)
[Docker] Create a jupyterLab (python) environment in 3 minutes!
Periodically execute python script with cron in venv environment
Japanese can be used with Python in Docker environment
venv environment with windows powershell
Python environment construction (Windows10 + Emacs)
Handle environment variables in Python
Build Python environment on Windows
Prepare python3 environment with Docker
Build a Python virtual environment using venv (Django + MySQL ①)
OpenVINO using Inference Engine Python API in PC environment
Build python environment on windows
venv: Python virtual environment management
Python environment construction under Windows7 environment
Python install in 2 lines @Windows
python standard virtual environment venv
Setting up Jupyter Lab in a Python 3.9 venv environment
Translate using googletrans in Python
Using Python mode in Processing
python3.8 venv environment jupyter notebook
How to use VS Code in venv environment on windows
How to implement Python EXE for Windows in Docker container
[Python] Show multiple windows in Tkinter
GUI programming in Python using Appjar
Python environment construction memo on Windows 10
Run eclipse in Docker environment (noVNC)
Precautions when using pit in Python
Anaconda python environment construction on Windows 10
Put MeCab in "Windows 10; Python3.5 (64bit)"
Build a go environment using Docker
Install python2.7 on windows 32bit environment
Python is UnicodeEncodeError in CodeBox docker
Install scrapy in python anaconda environment
Until you put Python in Docker
Build Mysql + Python environment with docker
Try using LevelDB in Python (plyvel)
Various Anaconda settings in Windows 10 environment
[Python3] Development environment construction << Windows edition >>
Windows10: Install MeCab library in python
install tensorflow in anaconda + python3.5 environment
Using global variables in python functions
Let's see using input in python
Infinite product in Python (using functools)
Edit videos in Python using MoviePy