Docker: "Unknown instruction: VIRTUALENV' - python

Dockerfile:
FROM ubuntu:14.04.2
RUN apt-get -y update && apt-get upgrade -y
RUN apt-get install python build-essential python-dev python-pip python-setuptools -y
RUN apt-get install libxml2-dev libxslt1-dev python-dev -y
RUN apt-get install libpq-dev postgresql-common postgresql-client -y
RUN apt-get install openssl openssl-blacklist openssl-blacklist-extra -y
RUN apt-get install nginx -y
RUN pip install virtualenv uwsgi
ADD canonicaliser_api ~
virtualenv ~/canonicaliser_api/venv
source ~/canonicaliser_api/venv/bin/activate
pip install -r ~/canonicaliser_api/requirements.txt
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
EXPOSE 80
CMD service nginx start
Build error:
...
Successfully installed virtualenv uwsgi
Cleaning up...
---> 0c141e23f725
Removing intermediate container d9fd3c20365d
Step 8 : ADD canonicaliser_api ~
---> 89b4fb40dba5
Removing intermediate container b0c1ad946fc4
Step 9 : VIRTUALENV
Unknown instruction: VIRTUALENV
is it supposed to remove those containers?
Why isn't it seeing virtualenv?

is it supposed to remove those containers?
Yes. If you want to keep them for some reason, pass --rm=false to the docker build command.
Why isn't it seeing virtualenv?
It is seeing it, but because it's at the start of a line, it treats it like a Dockerfile instruction, but there is no "VIRTUALENV" instruction. Presumably, you meant to put RUN before each line after the ADD:
ADD canonicaliser_api ~
RUN virtualenv ~/canonicaliser_api/venv
# This one needs to be a single RUN so the "source" will affect pip.
RUN source ~/canonicaliser_api/venv/bin/activate && \
pip install -r ~/canonicaliser_api/requirements.txt

Related

Unable to install PIP & PYMSSQL in docker

I am trying to build a docker image with
Python
PIP
pymssql
below is my Dockerfile
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get update && apt-get install -y telnet && apt-get install -y ksh && apt-get install -y python2.7.x && apt-get update && apt-get install -y python-pip python-dev build-essential && apt-get -y clean && rm -rf /var/lib/apt/lists/*
RUN pip install pymssql==2.1.3
ENTRYPOINT ['python']
it is throwing the following error:
If you don't mind to use python3 (otherwise use virtual env) I rate you to do :
RUN apt-get install python3-pip
Then you will be able to install whatever pip package you need : by doing :
RUN pip3 install <your_pip_pkg>
Python-pip is only available on Ubuntu Bionic. see python-pip.
You need to switch from focal to bionic. Universe repository should be enabled.

Run install python packages on Dockerfile

I'm new to Docker and currently trying to create a Dockerfile with installing the python packages and its libraries as shown here:
FROM balenalib/fincm3-debian-python:latest
# RUN install_packages git
RUN apt-get update && apt-get install python \
&& apt-get install pip3 \
apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev \
pip3 install pyaudio \
pip3 install numpy \
pip3 install matplotlib \
pip3 install scipy \
pip3 install librosa \
# Set our working directory
WORKDIR /usr/src/app
COPY Recorder.py /usr/src/app
# Recorder.py will run when container starts up on the device
CMD ["python","/usr/src/app/Recorder.py"]
However, while I am trying to push this Dockerfile, the error is generated with
Error: The command '/bin/sh -c apt-get update && apt-get install python && apt-get install pip3 apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev pip3 install pyaudio
pip3 install numpy pip3 install matplotlib pip3 install scipy pip3 install librosa WORKDIR /usr/src/app' returned a non-zero code: 100
Moving python packages in requirements.txt and installing python3-pip worked with python:3 base image.
# RUN install_packages git
RUN apt-get update \
&& apt-get install -y python \
&& apt-get install -y python3-pip
RUN pip install -r requirements.txt
The package you are looking for is called python3-pip.
Next, you need both && (to separate commands) and \ (to continue the command line). So, in summary, that should be:
FROM balenalib/fincm3-debian-python:latest
RUN apt-get update && apt-get install python && \
apt-get install -y \
python3-pip libportaudio0 libportaudio2 libportaudiocpp0 \
portaudio19-dev && \
pip3 install pyaudio numpy matplotlib \
scipy librosa
# Set our working directory
WORKDIR /usr/src/app
COPY Recorder.py /usr/src/app
# Recorder.py will run when container starts up on the device
CMD ["python","/usr/src/app/Recorder.py"]
I believe you have more than one problem in this Dockerfile, and when you put all commands together with && and \, you don't know which one is triggering the error. I suggest splitting them for debugging purposes, when they all work then you can put then together. Once you understand each individual error is easier to check and solve them. this question has valuable info: how to install pip in docker
Try this:
1- packages are triggers Y/n questions, give -y to guarantee it passes
2- using the backslashes to refer to a new command, you should use &&, backslashes refer to breaking line, you can use \ and then &&
3- pip3 and libportaudio0 packages doesn't exist.
E: Unable to locate package libportaudio0
I found out about the errors dividing the Dockerfile like this and removing the problems mentioned:
RUN apt-get update
RUN apt-get install python -y\
&& apt-get install python3-pip -y
RUN apt-get install libportaudio2 libportaudiocpp0 portaudio19-dev -y
RUN pip3 install pyaudio numpy matplotlib \
scipy librosa
If you want to put the commands together:
RUN apt-get update \
&& apt-get install python -y \
&& apt-get install python3-pip -y \
&& apt-get install libportaudio2 libportaudiocpp0 portaudio19-dev -y \
&& pip3 install pyaudio numpy matplotlib \
scipy librosa
I also suggest adding a pip requirements file, would make things cleaner.

I have getting 'apt-get upgrade' command failed error while building Python3.6-buster container

There was no problem yesterday when I build my Python Flask application on python:3.6-buster image. But today I am getting this error.
Calculating upgrade...
The following packages will be upgraded: libgnutls-dane0 libgnutls-openssl27 libgnutls28-dev libgnutls30 libgnutlsxx28
5 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 2859 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Abort.
ERROR: Service 'gateway' failed to build: The command '/bin/sh -c apt-get upgrade' returned a non-zero code: 1
My Dockerfile:
FROM python:3.6-buster
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN echo $TZ > /etc/timezone
RUN apt-get update
RUN apt-get upgrade
RUN apt-get -y install gcc musl-dev libffi-dev
COPY requirements.txt requirements.txt
RUN python3 -m pip install -r requirements.txt
COPY . /application
WORKDIR /application
EXPOSE 7000
I couldn't find any related question. I guest this is about a new update but I don't know actually. Is there any advice or solution for this problem?
I guess that apt is waiting for user input in order to confirm the upgrade. The Docker builder doesn't can't deal with these interactive dialogs without hacky solutions. Therefore, it fails.
The most straight forward solution is to add the -y flag to your commands as you do it on the install command.
FROM python:3.6-buster
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN echo $TZ > /etc/timezone
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get -y install gcc musl-dev libffi-dev
COPY requirements.txt requirements.txt
RUN python3 -m pip install -r requirements.txt
COPY . /application
WORKDIR /application
EXPOSE 7000
However... do you actually need to update your existing packages? That might be not required in your case. In addition, I might recommend that you check out the Docker Best Practices to write statements including apt commands. In order to keep your image size small, you should consider squashing these commands in a single RUN statement. In addition, you should delete the apt cache afterwards to minimize the changes between your two layers:
FROM python:3.6-buster
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN echo $TZ > /etc/timezone
RUN apt-get update \
&& apt-get -y install gcc musl-dev libffi-dev \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt requirements.txt
RUN python3 -m pip install -r requirements.txt
COPY . /application
WORKDIR /application
EXPOSE 7000

cant install pip in ubuntu 18.04 docker /bin/sh: 1: pip: not found

I am getting the error using pip in my docker image.
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y \
software-properties-common
RUN add-apt-repository universe
RUN apt-get install -y \
python3.6 \
python3-pip
ENV PYTHONUNBUFFERED 1
RUN mkdir /api
WORKDIR /api
COPY . /api/
RUN pip install pipenv
RUN ls
RUN pipenv sync
I installed python 3.6 and pip3 but getting
Step 9/11 : RUN pip install pipenv
---> Running in b184de4eb28e
/bin/sh: 1: pip: not found
To run pip for python3 use pip3, not pip.
Another solution.
You can add this line (after apt-get install). It will upgrade pip to the version you need, for instance:
RUN pip3 install --upgrade pip==20.0.1
and you can then use pip install from requirements file (for instance):
RUN pip install -r requirements.txt

Python in docker container

I am new to Docker so I am sorry for such an easy question.
I am building a docker container which is built on top of a image which is built on ubuntu:vivid image.
When executing my script within the container I am getting an error:
exec: "python": executable file not found in $PATH
How can I solve this?
When I try to run apt-get install python in my Docker file:
FROM my_image # based on ubuntu:vivid
RUN apt-get update && \
apt-get install -y python3
ENV PATH /:$PATH
COPY file.py /
CMD ["python", "file.py", "-h"]
I get:
WARNING: The following packages cannot be authenticated!
libexpat1 libffi6 libmagic1 libmpdec2 libssl1.0.0 libpython3.4-minimal
mime-support libsqlite3-0 libpython3.4-stdlib python3.4-minimal
python3-minimal python3.4 libpython3-stdlib dh-python python3 file
E: There are problems and -y was used without --force-yes
The command '/bin/sh -c apt-get update && apt-get install -y python3' returned a non-zero code: 100
make: *** [image] Error 1
EDIT: added Dockerfile content
You have similar issue with some Linux distribution: "Why am I getting authentication errors for packages from an Ubuntu repository?"
In all cases, the usual sequence of command to install new packages is:
RUN apt-get update -yq && apt-get install -yqq \
git \
python \
...
The OP Ela reports in the comments:
RUN apt-get update -y && apt-get install -y --force-yes \
git \
python \
...
You are installing python3 and then you use the executable of python, I had the same issue and I have resolved using python3.
Try changing your last line of your Dockerfile :
instead of
CMD ["python", "file.py", "-h"]
try :
CMD ["python3", "file.py", "-h"]

Categories

Resources