I'm running a python script to manipulate pictures. I was using an ImageMagick binding for python called wand.
Here is the Dockerfile.
FROM ubuntu:latest
RUN apt update
RUN apt install python3 -y
RUN apt-get -y install python3-pip
RUN pip install pillow
RUN pip install wand
WORKDIR /usr/app/src
COPY image_converter.py ./
COPY test_image_converter.py ./
RUN python3 -m unittest test_image_converter.py
And this is the error message
ImportError: MagickWand shared library not found.
You probably had not installed ImageMagick library.
Try to install:
https://docs.wand-py.org/en/latest/guide/install.html
Alright I got it thanks to this one Docker unantended installation of imagemagick
RUN DEBIAN_FRONTEND="noninteractive" apt-get install libmagickwand-dev --no-install-recommends -y
Related
I am trying to create a docker image from my docker file which has the following content:
FROM ubuntu:latest
WORKDIR /app
ADD . /app
RUN apt-get update && apt-get install python -y
CMD python /app/main.py
LABEL color=red
which fails with the following error:
apt-get update && apt-get install python -y returned a non-zero code: 100
So please help me in solving this error
Docker is just Linux. When some apt-get install acme fails, you just need to try the exact command and or research the missing dependencies.
To replicate your error I ran: docker run -it ubuntu:latest and inside, I ran your apt-get update && apt-get install python -y. I got the error:
So, I tried with apt-get install python3 -y and it worked. Finally your Dockerfile should be:
FROM ubuntu:latest
WORKDIR /app
ADD . /app
RUN apt-get update && apt-get install python3 -y
CMD python3 /app/main.py
LABEL color=red
Older Python
If your code needs old python version, you should not use FROM ubuntu:latest because in the lastest version of ubuntu, only python3 is allowed.
Anyway if you need python2, you must research a lot on internet to get the exact steps to install python2 or use some ready to use docker images:
https://hub.docker.com/layers/python/library/python/2.7.18-slim-stretch/images/sha256-a0b3c65a15ba08138460de9fd2267b8dec30ed98407a0edac0adc0ccbe809cad?context=explore
how do i setup only python 2.7 in docker container?
https://github.com/Docker-Hub-frolvlad/docker-alpine-python2
I've build an application which is detecting and tracking region of interest. It workers absolutely fine in my local machine, but when I am dockerazing the app I get this error:
"qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in "" " on opencv version 4.5.5.64.
When I downgrade to opencv version 4.1.2.30, it then starts working( Note I want to work on Opencv 4.5.5.64 for tracker related issues).
I am running docker image like: sudo docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix --device /dev/video0 --gpus all --ipc=host myImage.
Its working with older version of opencv but not with 4.5.5.64. I've been banging my head on this issue since last 4 days now, I would really appreciate if I can get some help
FROM nvcr.io/nvidia/pytorch:22.04-py3
RUN rm -rf /opt/pytorch
RUN apt-get update && apt-get autoclean
RUN apt-get update && apt-get install -y --no-install-recommends python3-pip
RUN pip3 install pyqt5
RUN apt-get install -y '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
RUN apt-get install -y libsm6 libxrender1 libfontconfig1
ENV QT_DEBUG_PLUGINS=1
COPY requirements.txt .
RUN python -m pip install --upgrade pip
RUN pip uninstall -y torch torchvision torchtext Pillow
RUN pip install --no-cache -r requirements.txt albumentations wandb gsutil notebook Pillow>=9.1.0 \
torch torchvision --extra-index-url https://download.pytorch.org/whl/cu113
RUN pip install opencv-contrib-python==4.5.5.64
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
ENV OMP_NUM_THREADS=8
below is the dockerfile content.
I'm trying to run the below Dockerfile contents on ubuntu image.
FROM ubuntu
RUN apt-get update
RUN apt-get install -y python
RUN apt-get install -y python-pip
RUN pip install flask
COPY app.py /opt/app.py
ENTRYPOINT FLASK_APP=/opt/app.py flask run --host=0.0.0.0
But i'm getting the below error at layer 3.
Step 1/7 : FROM ubuntu
---> 549b9b86cb8d
Step 2/7 : RUN apt-get update
---> Using cache
---> 78d87d6d9188
Step 3/7 : RUN apt-get install -y python
---> Running in a256128fde51
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package python
Athough while I run the below command individually
sudo apt-get install -y python
It's successfully getting installed.
Can anyone please help me out.
Note: I'm working behind organization proxy.
Step 2/7 : RUN apt-get update
---> Using cache
You should run apt-get update and apt-get install in the same RUN instruction as follows
RUN apt-get update && apt-get install -y python
Each instruction in a Dockerfile will create separate layer in the image and the layers are cached. So the apt-get update might just use cache and not even run. This has happened in your case as well. You can see the line ---> Using cache in your logs. You can use docker build --no-cache to make docker rebuild all the layers without using cache.
You can instead just use python:3 official image as base image to run your python apps.
In the python installation tutorial there is a package name python3.x for Debian.
I think this is your case. I tested it in the Docker and this is right configuration
looks like
From ubuntu:20.04
RUN apt-get update && apt-get -y install python3.8 python3.8-dev
I feel you should rather use Python3 's image instead of using ubuntu and then installing it.
FROM python:3
RUN apt-get update && apt-get install -y python3-pip #You don't need to install pip, because it is already there in python's image
RUN pip install -r requirements.txt
COPY . /usr/src/apps #This you can change
WORKDIR /usr/src/apps/ #this as well
CMD ["python","app.py"]
Try the following, it worked for me
apt-get install python3-pip
And then for installing flask you will have to use
pip3 install flask
I am newbie in docker, but I have searched so much about the problem I am facing.
I am having a code in which I am using tensorflow, PyQt and other packages. Now, I have pulled the tensorflow/tensorflow:1.4.0-gpu-py3 and nvidia/cuda:8.0-cudnn6-runtime. Also I have build the image of my application with some dependencies.
I tried to run all the above images with the docker-compose as below:
version: '3'
services:
nvidia:
image: "nvidia/cuda:8.0-cudnn6-runtime"
tensorflow:
image: "tensorflow/tensorflow:1.4.0-gpu-py3"
app:
image: my_app
But I am getting error ImportError: No module named 'tensorflow'.
Please help me by suggesting the way I should solve this.
Edit:
Following code sample is just few lines of my code.
import sys
from PyQt5 import QtCore, QtGui, QtQml, QtQuick
from OpenGL import GL
import cv2 # .cv2 as cv2
from multiprocessing import Process,Queue, Value, Manager
import os
import tensorflow as tf
Edit:
# Use an official Python runtime as a parent image
FROM ubuntu:16.04
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
RUN \
apt-get update && \
apt-get install -y python python-dev python-pip python-virtualenv && \
rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils && apt-get install -y libgtk2.0-dev python python-dev python3 python3-dev python3-pip
RUN apt-get update && apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
RUN pip install setuptools pip --upgrade --force-reinstall
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
#RUN apt-get update -y
# Install packages
#RUN apt-get install -y curl
#RUN apt-get install -y postgresql
#RUN apt-get install -y postgresql-client
#RUN apt-get install -y python3-numpy python3-opengl python-qt4 python-qt4-gl
# Run app.py when the container launches
CMD ["python3", "Working.py"]
requirement.txt
PyOpenGL
PyQt5
opencv-python
You have 3 separate docker containers, Nvidia, Tensorflow, And you application.
When you include tensorflow in python application, there is no Tensorflow package there, it is in separate container.
Suggestion is to remove Tensor-flow container, and add app into tensorflow image.
In you Dockerfile change FROM image:
FROM ubuntu:16.04 to FROM tensorflow/tensorflow:1.4.0-gpu-py3
Then change other parts of Dockerfile installation, because tensorflow image already have python3 installed.
I'm trying to get a rails server setup on a raspberry pi by building a Docker image.
Image:
FROM ruby:latest
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
RUN apt-get install -y nodejs
WORKDIR /webapp
COPY Gemfile* /webapp
RUN bundle install
COPY . /webapp/
CMD ["rails", "s", "-b", "0.0.0.0"]
But I'm getting
E: Package 'nodejs' has no installation candidate
EDIT:
I have tried adding the command from the nodejs site curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get install -y nodejs
The reason the error Package 'nodejs' has no installation candidate was showing up regardless of how you tried to add the repo to apt-get is because Skipping acquire of configured file 'main/binary-armel/Packages' as repository 'https://deb.nodesource.com/node_10.x stretch InRelease' doesn't support architecture 'armel'.
My solution was to move to an arm32v7/ruby base image and running the same commands. This will install the nodejs_4.8.2~dfsg-1_armhf.deb package which is compatible with the arm architecture.