I am new to Docker and am currently having issues importing local python files into my Flask application using a Dockerfile
File hierarchy:
survey_tool
cli
survey_input.py
web
app.py
Current Dockerfile:
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY cli /app
COPY web /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["app.py"]
In my application, I am trying to run a method from another python file (called gui_prompt).
When I try to build the app, the app immediately crashes and gives me this stack trace when running the docker logs file on the container id:
File "app.py", line 3, in <module>
from cli.survey_input import gui_prompt
ImportError: No module named cli.survey_input
Am I not importing the cli folder correctly?
Related
I'm new to docker and I'm trying to create a docker image in which a python 2.7 script runs. This file imports functions and classes from other files in the same directory. Building the docker image already works, but running it gives an error that the imported files in the python 2.7 script don't exist.
This is the dockerfile I'm using
FROM python:2.7
WORKDIR C:\something\something\print
RUN apt-get update
RUN apt-get install python-cairo
RUN apt-get install python-gi
RUN apt-get install python-gi-cairo
RUN apt-get install -y gir1.2-gtk-3.0
RUN apt-get install -y mapnik-utils
RUN pip install bs4
RUN pip install image
RUN pip install mapnik
RUN pip install numpy
RUN pip install psycopg2
COPY test_server.py ./
CMD [ "python", "./test_server.py"]
And this is the error I receive after I do "docker run"
Traceback (most recent call last):
File "./test_server.py", line 13, in <module>
from utils import client, reprojector, formats
ImportError: No module named utils
The module named utils is a folder in the WORKDIR I specified in the dockerfile, but I don't understand why it can't be accessed. What am I doing wrong here?
Hope you are having a nice day.
So I have encountered a difficulty with uploading my Flask app on the web using Heroku, because my app uses a .DLL library, and Heroku's server are using Linux as their OS, so .DLL seems not to be compatible.
Now I have read online that Dockerfile allows you to bypass this limitation by creating a container that somehow can be ran on any OS.
The Dockerfile topic is new to me. I need some help about what Instructions to write in my Dockerfile to boot the Flask app while having the .DLL library into memory.
Here is what I currently have in the Dockerfile. It doesn't work. What should I write in there?
FROM ubuntu:16.04
RUN apt-get update -y && \
apt-get install -y python-pip python-dev
# We copy just the requirements.txt first to leverage Docker cache
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY . /app
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]
Thank you for your help.
This is my first Dockerfile and this is what I have so far.
FROM python:3.6-stretch
# install build utilities
RUN apt-get update && \
apt-get install -y gcc make apt-transport-https ca-certificates build-essential
# check our python environment
RUN python3 --version
RUN pip3 --version
# set the working directory for containers
WORKDIR /usr/src/toxic-content-monitoring
# Installing python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy all the files from the project’s root to the working directory
COPY src/ /src/
RUN ls -la /src/*
# Running Python Application
CMD ["python3", "/src/main.py"]
But when I am trying to run the docker image the files inside the data folder cannot be found.
Here is a picture of the my project structure.
Changed it to what was suggested and still getting an error.
FROM python:3.6-stretch
# install build utilities
RUN apt-get update && \
apt-get install -y gcc make apt-transport-https ca-certificates build-essential
# check our python environment
RUN python3 --version
RUN pip3 --version
# set the working directory for containers
WORKDIR /usr/src/toxic-content-monitoring
# Installing python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy all the files from the project’s root to the working directory
COPY src/ /src/
COPY data /data/
RUN ls -la /src/*
# Running Python Application
CMD ["python3", "/src/main.py"]
This is the error message.
docker run toxic-content-monitoring:0.1
wiki.en.vec: 6.60GB [10:05, 10.9MB/s]
0%| | 0/2519371 [00:00<?, ?it/s]Skipping token 2519370 with 1-dimensional vector ['300']; likely a header
100%|██████████| 2519371/2519371 [08:36<00:00, 4878.67it/s]
Traceback (most recent call last):
File "/src/main.py", line 11, in <module>
from preprocessor import normalize_comment, clean_text
File "/src/preprocessor.py", line 42, in <module>
word_file = open(link, "r")
FileNotFoundError: [Errno 2] No such file or directory: 'data/identity_hateWordFile.txt'
I believe your Dockerfile is missing COPY data/ /data/ command in it. You are only doing a copy of src folder and not data. Please include COPY data /data/ right after COPY src/ /src/ line in your Dockerfile and give it a try.
In the Docker file, I get this error
ImportError: No module named flask
Here is the Docker file
FROM continuumio/anaconda3
MAINTAINER kumar
COPY ./flask_master /usr/local/python
EXPOSE 5000
WORKDIR /usr/local/python
RUN apt-get update && apt-get install -y python3-pip
RUN pip3 install -r requirements.txt
CMD python flaskPredictAPI.py
Here is the requirements.txt
flask
flasgger
joblib
But when I run it, I get this
docker run -i -t -p 5000:5000 randomforestapi
Traceback (most recent call last):
File "flaskPredictAPI.py", line 1, in
from flask import Flask, request
ImportError: No module named flask
Are you able to build your docker image successfully? Did you checked if during build the requirements.txt gets executed without any error? I would suggest you generate your requirements.txt using below command in your project folder.
pip freeze > requirements.txt
It would look something like this
click==7.1.2
Flask==1.1.2
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
Werkzeug==1.0.1
I'm trying to connect my .net core application, hosted on a unix docker container to an external Vertica database.
It works fine when it's a windows client because there are Vertica Drivers for Windows. But there isn't a unix driver for Vertica under unix.
When I try to run a Query against Vertica I get the following error:
Dependency unixODBC with minimum version 2.3.1 is required. Unable to
load shared library 'libodbc.so.2' or one of its dependencies. In
order to help diagnose loading problems, consider setting the LD_DEBUG
environment variable: liblibodbc.so.2.so:
My docker file looks like this
FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app
ARG DEBIAN_FRONTEND=noninteractive
# Copy csproj and restore as distinct layers
COPY ./*.sln ./
COPY ./MyApp/*.csproj ./MyApp/
RUN dotnet restore MyApp.sln
COPY . ./
RUN dotnet publish MyApp.sln -c Release -f=netcoreapp2.1 -o out
RUN cp /app/MyApp/*.yml /app/MyApp/out
RUN cp /app/*.ini /app/VMyApp/out
#ODBC
FROM microsoft/dotnet:aspnetcore-runtime
RUN apt-get update
RUN apt-get install -y apt-utils
RUN curl -O -k https://www.vertica.com/client_drivers/9.1.x/9.1.1-0/vertica-client-9.1.1-0.x86_64.tar.gz
RUN tar vzxf vertica-client-9.1.1-0.x86_64.tar.gz && rm vertica-client-9.1.1-0.x86_64.tar.gz
RUN apt-get install -y unixodbc-dev
ADD odbc.ini /root/odbc.ini
ADD odbcinst.ini /root/odbcinst.ini
ADD vertica.ini /root/vertica.ini
ENV VERTICAINI=/root/vertica.ini
ENV ODBCINI=/root/odbc.ini
RUN echo "$VERTICAINI $ODBCINI"
WORKDIR /app
COPY --from=build-env /app/MyApp/out .
ENTRYPOINT ["dotnet", "MyApp.dll"]