0

I have the following problem: I have to build a docker image for Ubuntu 16.04 and Python 3.8 (it is required to use MSSQL 16 for Django and I have to use MSSQL 16), but no official Python image for Docker exists for this version.

I'm working on Windows with Docker Desktop on a VM. I came to the following Dockerfile (I had to avoid apt-get install python3.8 or pip because this ubuntu version is no longer supported):

FROM ubuntu:16.04

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1

WORKDIR /app

# Update the package list and install necessary packages
RUN apt-get update && \
    apt-get install -y wget build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev  \
    libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev libffi-dev uuid-dev  \
    apt-transport-https gnupg2 curl

# Download Python 3.8.15 source
RUN wget https://www.python.org/ftp/python/3.8.15/Python-3.8.15.tgz && \
    tar xvf Python-3.8.15.tgz && \
    cd Python-3.8.15 && \
    ./configure --enable-optimizations && \
    make -j 3 && \
    make install && \
    cd .. && \
    rm -rf Python-3.8.15 && \
    rm Python-3.8.15.tgz

# Add Python 3.8 binary path to the PATH environment variable
ENV PATH="/usr/local/bin:${PATH}"

# Install pip for Python 3.8
RUN wget https://bootstrap.pypa.io/get-pip.py && \
    python3 get-pip.py && \
    rm get-pip.py

# Download poppler and Microsoft ODBC driver (instructions at https://github.com/MicrosoftDocs/sql-docs/blob/live/docs/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server.md#13)
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
    curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
    apt-get update && \
    ACCEPT_EULA=Y apt-get install -y msodbcsql=13.0.1.0-1 mssql-tools=14.0.2.0-1 unixodbc-dev-utf16 libodbc1-utf16 \
    poppler-utils

# populate "ocbcinst.ini"
RUN echo "[ODBC Driver 13 for SQL Server]\n\
Description = Microsoft ODBC Driver 13 for SQL Server\n\
Driver = /opt/microsoft/msodbcsql13/lib64/libmsodbcsql-17.2.so.0.1\n\
UsageCount=1" >> /etc/odbcinst.ini

# requirements for dev
COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

COPY . .
EXPOSE 8000
CMD ["echo", "$PATH"]

# CMD ["python3", "--version"]
#"manage.py", "runserver", "0.0.0.0:8000"

Now, it seems to run, but it tells me I have a Python error while I don't use python in my CMD command ?

[+] Running 2/2
 ✔ Network autocheck_default  Created                                                                                         2.1s 
 ✔ Container autocheck_web    Created                                                                                         6.9s 
Attaching to autocheck_web
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create
 failed: unable to start container process: exec: "python": executable file not found in $PATH: unknown

Could someone help me to know what's wrong here? I tried to prune docker and $env:COMPOSE_HTTP_TIMEOUT=480 (trying to get ideas here) but it didn't work. And if there's a faster way to build the docker image, I would gladly do that, because it takes a lot of time!

Thanks a lot !

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Paanik
  • 1
  • Your `ENV PATH` seems not to have worked. – OneCricketeer Aug 03 '23 at 22:34
  • Why can't you use `FROM python:3.8` image? Those definitely exist https://hub.docker.com/_/python/tags?page=1&name=3.8 *and* will take less time since you dont need to build python from source – OneCricketeer Aug 03 '23 at 22:35
  • @OneCricketeer I can't because I need Ubuntu16.04 to make MSSQL work with django, and FROM python:3.8 uses Debian12 – Paanik Aug 04 '23 at 08:22
  • Unclear why you need such an old version of Ubuntu. What specific error do you get that mentions any required Ubuntu version? Django and MSSQL dont care about that. More specifically, your container runs completely separate from the database and OS information is not sent in a network request to it – OneCricketeer Aug 04 '23 at 16:41
  • seems that you trying to launch _python_ instead of _python3_ I've tried building your docker file and it worked. Check your _manage.py_ script, it probably has wrong shebang _#!/bin/python_ – Monsieur Merso Aug 06 '23 at 15:31

0 Answers0