Docker build was ok, and the Python script (app) that was inside could be executed perfectly too. I hadn't touched the code for some months now, but I recently did a general, across-system software update in my Oracle VM VirtualBox Ubuntu 20.04.3 LTS x86_64. I thought this wouldn't affect my docker, since I had specified package versions, etc.
However, when I try to docker build now it cannot find TensorFlow 2.12.0, and says that only 12.16.0rc and 12.16.1 are available. How can I make it see the 2.12.0 version again? Here is my Dockerfile:
# Build stage
FROM python:3.7-slim AS build
WORKDIR /todo
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PATH="/root/miniconda3/bin:${PATH}"
ARG PATH="/root/miniconda3/bin:${PATH}"
RUN apt-get update
RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*
RUN wget \
https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
&& mkdir /root/.conda \
&& bash Miniconda3-latest-Linux-x86_64.sh -b \
&& rm -f Miniconda3-latest-Linux-x86_64.sh
RUN conda --version
RUN apt-get --purge autoremove -y wget
RUN python -m pip install --no-cache-dir --no-deps tensorflow-cpu==2.12.0 # <--- ERROR HERE
# Runtime stage
FROM python:3.7-slim
WORKDIR /todo
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
COPY --from=build /root/miniconda3 /root/miniconda3
COPY requirements.txt requirements.txt
COPY get_predict_m_data.py get_predict_m_data.py
ENV PATH="/root/miniconda3/bin:${PATH}"
ENV PATH="/usr/local/lib/:${PATH}"
RUN pip3 install --no-cache-dir -r requirements.txt
ENV PORT 5556
EXPOSE 5556
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
CMD ["python", "-u", "get_predict_m_data.py"]
Error:
gsamaras@lv74744332234a:~/Code$ sudo docker build --no-cache -t predict_api .
[sudo] password for gsamaras:
[+] Building 36.1s (14/23) docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 1.68kB 0.0s
=> [internal] load metadata for docker.io/library/python:3.7-slim-buster 3.4s
=> [auth] library/python:pull token for registry-1.docker.io 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [build 1/8] FROM docker.io/library/python:3.7-slim-buster@sha256:9bd2bfc822a533f99cbe6b1311d5bf0ff136f776ebac9b985407829f17278935 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 533B 0.0s
=> CACHED [build 2/8] WORKDIR /todo 0.0s
=> [build 3/8] RUN apt-get update 6.5s
=> CANCELED [stage-1 3/12] RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* 32.7s
=> [build 4/8] RUN apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/* 2.9s
=> [build 5/8] RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && mkdir /root/.conda && bash Miniconda3-latest-Linux-x86_64.sh -b && rm -f Miniconda3-latest-Linux- 20.8s
=> [build 6/8] RUN conda --version 0.5s
=> [build 7/8] RUN apt-get --purge autoremove -y wget 0.5s
=> ERROR [build 8/8] RUN python -m pip install --no-cache-dir --no-deps tensorflow-cpu==2.12.0 1.4s
------
> [build 8/8] RUN python -m pip install --no-cache-dir --no-deps tensorflow-cpu==2.12.0:
1.094 ERROR: Could not find a version that satisfies the requirement tensorflow-cpu==2.12.0 (from versions: 2.16.0rc0, 2.16.1)
1.094 ERROR: No matching distribution found for tensorflow-cpu==2.12.0
------
Dockerfile:22
--------------------
20 | RUN apt-get --purge autoremove -y wget
21 |
22 | >>> RUN python -m pip install --no-cache-dir --no-deps tensorflow-cpu==2.12.0
23 |
24 | # Runtime stage
--------------------
ERROR: failed to solve: process "/bin/sh -c python -m pip install --no-cache-dir --no-deps tensorflow-cpu==2.12.0" did not complete successfully: exit code: 1
If I go with a newer TF version, then a chain reaction happens with many dependencies getting broken, I can show the requirements.txt too if needed. If I update all the dependencies (and install new required packages), then I am getting a series of runtime errors, which when I fix, I hit compatibility issues (Keras 2 with Keras 3 trained models), which requires a lot of work; thus I seek a way to work with TF 2.12.0, in order for everything to be harmonized.
Looking at the pypi package for tensor tensorflow-gpu, it seems that package has been removed. They write the following:
tensorflow-gpu has been removed. Please install tensorflow instead. The tensorflow package supports GPU accelerated operations via Nvidia CUDA.
tensorflow and tensorflow-gpu have been the same package since TensorFlow 2.1, released in September 2019. Although the checksums differ due to metadata, they were built in the same way and both provide GPU support via Nvidia CUDA. As of December 2022, tensorflow-gpu has been removed and has been replaced with this new, empty package that generates an error upon installation.
All existing versions of tensorflow-gpu are still available, but the TensorFlow team has stopped releasing any new tensorflow-gpu packages, and will not release any patches for existing tensorflow-gpu versions.
This simple package raises a warning if setup.py is executed as part of a package installation. This intentionally prevents users from installing the package.
Try changing tensorflow-cpu==2.12
to tensorflow==2.12
As can be seen on the pypi package for tensorflow, the minimum required version of python is 3.8
. You are using 3.7
. Try updating from:
FROM python:3.7-slim AS build
to FROM python:3.8-slim AS build