# Docker (julia:1.7.0-alpine3.15) with custom Python Enviroment

**URL:** <https://discourse.julialang.org/t/docker-julia-1-7-0-alpine3-15-with-custom-python-enviroment/73089>\
**Category:** Tooling\
**Tags:** pycall, windows, linux, python, docker\
**Created:** [December 14, 2021, 6:55pm UTC](https://discourse.julialang.org/t/docker-julia-1-7-0-alpine3-15-with-custom-python-enviroment/73089 "2021-12-14T18:55:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pytrator](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@Pytrator](https://discourse.julialang.org/u/Pytrator)\
**Post date:** [December 14, 2021, 6:55pm UTC](https://discourse.julialang.org/t/docker-julia-1-7-0-alpine3-15-with-custom-python-enviroment/73089/1 "2021-12-14T18:55:41Z")

</div>

Hey there, I am trying to create a Docker-Template for anyone who wants to run their projects in Docker/Apline with a custom Python Version.

Currently, I´m getting this issue and I don’t know how to fix it. There are plenty of people out there saying “unset” Pythonhome ENV but this wasn’t working for me too.

```julia
Python path configuration:
  PYTHONHOME = '/root/.pyenv/versions/3.7.8:/root/.pyenv/versions/3.7.8'
  PYTHONPATH = (not set)
  program name = '/root/.pyenv/versions/3.7.8/bin/python'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/root/.pyenv/versions/3.7.8/bin/python'
  sys.base_prefix = '/root/.pyenv/versions/3.7.8'
  sys.base_exec_prefix = '/root/.pyenv/versions/3.7.8'
  sys.platlibdir = 'lib'
  sys.executable = '/root/.pyenv/versions/3.7.8/bin/python'
  sys.prefix = '/root/.pyenv/versions/3.7.8'
  sys.exec_prefix = '/root/.pyenv/versions/3.7.8'
  sys.path = [
    '/root/.pyenv/versions/3.7.8/lib/python39.zip',
    '/root/.pyenv/versions/3.7.8/lib/python3.9',
    '/root/.pyenv/versions/3.7.8/lib/python3.9/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

```

This is my Dockerfile

```julia
FROM julia:1.7.0-alpine3.15

WORKDIR /app
ADD / /app

RUN apk add linux-headers
# Update & Install dependencies
RUN apk add --no-cache --update \
    git \
    bash \
    libffi-dev \
    openssl-dev \
    bzip2-dev \
    zlib-dev \
    readline-dev \
    sqlite-dev \
    build-base

# Set Python version
ARG PYTHON_VERSION='3.7.8'
# Set pyenv home
ARG PYENV_HOME=/root/.pyenv

# Install pyenv, then install python versions
RUN git clone --depth 1 https://github.com/pyenv/pyenv.git $PYENV_HOME && \
    rm -rfv $PYENV_HOME/.git

ENV PATH $PYENV_HOME/shims:$PYENV_HOME/bin:$PATH

RUN pyenv install $PYTHON_VERSION
RUN pyenv global $PYTHON_VERSION
RUN pip install --upgrade pip && pyenv rehash

# Clean
RUN rm -rf ~/.cache/pip

# Installs Stuff for Alpine
RUN apk --update add libxml2-dev libxslt-dev libffi-dev gcc musl-dev libgcc openssl-dev curl
RUN apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev
RUN apk add python3-dev

# Installs your Python stuff
RUN pip install -r requirements.txt

RUN julia -e 'ENV["PYCALL_JL_RUNTIME_PYTHONHOME"]="/root/.pyenv/versions/3.7.8/bin/python"'
RUN julia -e 'ENV["PYTHON"]="/root/.pyenv/versions/3.7.8/bin/python"; using Pkg; Pkg.add("PyCall"); Pkg.build("PyCall"); Pkg.instantiate(); Pkg.precompile()'

ENTRYPOINT ["julia"]
CMD ["src/docker_runs_checker.jl"]

```

Here you find all project files [https://github.com/MalteBoehm/julia\_docker-compose\_template](https://github.com/MalteBoehm/julia_docker-compose_template)

Thanks for the help.
