I'm new in the docker world.
I have a Dockerfile that emulates a linux machine and that i use to connect to a microsoft SQL.
FROM ubuntu:20.04
WORKDIR /app
ADD . /app
RUN apt dist-upgrade
RUN apt-get clean
RUN apt-get -y update
RUN apt-get -y install unixodbc unixodbc-dev openssl libkrb5-3 tdsodbc build-essential gcc curl coinor-cbc
RUN apt-get -y install python3.7 python3-pip python3-dev python3-tzlocal
# driver "ODBC Driver 17 for SQL Server"
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/19.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get -y update
RUN ACCEPT_EULA=Y apt-get install msodbcsql17
RUN apt-get clean
RUN pip3 install -r requirements.txt
RUN chmod -R 777 ./
EXPOSE 8080
CMD python3 app.py
with RUN apt-get -y install tdsodbc i install a driver called freeTDF (documentation https://www.freetds.org/)
while here i install the ODBC drivers
RUN curl https://packages.microsoft.com/config/ubuntu/19.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get -y update
RUN ACCEPT_EULA=Y apt-get install msodbcsql17
RUN apt-get clean
which drivers do I actually use? what I can write in the shell to check that?
thank you.
my problem is: I need to run an app (named app in the docker) that do a lot of queries. I need to have the chance to do concurrent queries on the same connection. meaning at least that if I open two connections on Database1 and on both connections i do one query the two can be evaluated at the same time and not the first one waiting for the end of the first (I'm in this situation right now and I don't know why)
thank you
EDIT:
i tried docker info on the shell. no information about ODBC, SQL or microsoft are given. here the detail
below command give you information about storage driver you are using.
docker info
Related
Wanted to turn my python script into api using Docker.
This is what the Dockerfile looks like:
FROM python:3.9-slim
WORKDIR /app
RUN apt-get update && apt-get install -y \
build-essential \
software-properties-common \
git \
&& apt-get install poppler-utils -y \
&& apt-get -y install tesseract-ocr \
&& apt-get update \
&& apt-get install ffmpeg libsm6 libxext6 -y \
&& apt-get install default-libmysqlclient-dev -y \
&& rm -rf /var/lib/apt/lists/*
COPY . .
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
Docker build container just fine. It is running
No errors within the Docker:
I press the link and its just http://0.0.0.0/
I am using PyCharm and python, so I binded the port in PyCharm too
Did anyone run into similar problem? I am new to Docker and might've missed something obvios, sorry.
I tried adding port manually http://0.0.0.0:80/ and http://0.0.0.0:80/Docs
but nothing shows up.
I build similar project with exactly same parameters but this one doesn't work.
What your program is showing you is what address it has bound to. 0.0.0.0 means that it'll accept connections from anywhere and 0.0.0.0 isn't the actual address you need to talk to to reach your program.
You've mapped port 80 in the container to port 80 on the host, so you should be able to reach your program at http://localhost:80/. Since port 80 is the default for http, you can also just use http://localhost/.
I'm trying to create a flask-docker project, but i also need some tools from linux.
So i have a debian:latest base image for my dockerfile, in which i want to install
python3 and dieharder(the package i need for my project).
But every time i try to build the image with following command:
docker build --no-cache --pull -t backend .
I get 3 packages that fail to fetch:
E: Failed to fetch http://deb.debian.org/debian/pool/main/g/gcc-defaults/gcc_10.2.1-1_amd64.deb Bad header line Bad header data [IP: 151.101.14.132 80]
E: Failed to fetch http://deb.debian.org/debian/pool/main/g/gcc-defaults/g%2b%2b_10.2.1-1_amd64.deb Bad header line Bad header data [IP: 151.101.14.132 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
The command '/bin/sh -c apt-get update --fix-missing -y && apt-get install -y python3-pip && apt-get install -y dieharder' returned a non-zero code: 100
I'm already running everything in one RUN command and also using --no-cache, but i still
get these errors. Also i could'nt find anyone else with these specific errors.
So i'm asking for Your help, because i don't know what else i can do.
My Dockerfile:
FROM debian:latest
RUN apt-get update --fix-missing -y && apt-get install -y python3-pip && apt-get install -y dieharder
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY . /app
ENTRYPOINT [ "python" ]
CMD ["main.py"]
Could it be a problem that im doing all this on a VM? Is there any further information
you need to help me? Please let me know, this is my first question ever, so sry if it's not that good :)
P.S. i don't really need to use debian as a base image but i would prefer to. I also tried Ubuntu and got the same error, so i don't think that thats the problem.
Update:
It seems like i solved this problem, although I'm not really sure why it works now.
I had to change my run command and install gcc and g++ independently from
apt-get update. I don't know if this is an elegant solution, but it works for now.
If anyone has a smoother solution pls let me know :)
Anyway here is my final Dockerfile:
FROM debian:latest
RUN apt-get update -y && apt-get install gcc-10 -y && apt-get install g++-10 -y && apt-get install -y python3-pip && apt-get install -y dieharder
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY . /app
ENTRYPOINT [ "python3" ]
CMD ["main.py"]
Running into an expected issue trying to prepare an ubuntu 20.04 based image with python and pyodbc.
FROM ubuntu:20.04
# install mssql odbc driver
RUN apt-get update && apt-get upgrade -y && apt-get install -y curl gnupg build-essential
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql17 unixodbc-dev
# install python 3.7.9 from source
RUN apt-get install -y python3 python3-pip
# clean up
# this does not work
RUN apt-get remove -y perl curl gnupg && apt-get autoremove -y
# this works
# RUN apt-get remove -y curl gnupg && apt-get autoremove -y
RUN pip3 install pyodbc
If perl is not removed, the installation of pyodbc is uneventful, but if perl is removed, the following error is displayed:
src/pyodbc.h:56:10: fatal error: sql.h: No such file or directory
As if the unixodbc-dev is also removed for some reason. Has anyone run into this before? If perl is required, wouldn't apt-get prevent it from being deleted? Or I need to install a different set of c-bindings to make this work.
Also running apt-get install -f after installing msodbcsql17 doesn't help either.
Thanks.
unixodbc-dev was installed as a transitive dependency and was automatically removed when no longer needed, i.e. after perl was removed. You need to install it explicitly:
RUN apt-get install -y unixodbc-dev
See the following bug report for details: https://github.com/mkleehammer/pyodbc/issues/441
My docker build is failing after there is an update to this package (https://packages.microsoft.com/debian/9/prod/dists/stretch/main/binary-amd64/Packages.bz2) I want a version of this package before the update happened (24-Jun-2020 15:09 ).
after adding the URL to source.list, apt-get update -y is failing.
Docker File :
FROM python:3.6.8
WORKDIR /app
ADD . /app
RUN apt-get update -y
RUN apt-get install python-pip -y
RUN apt-get -y update && apt-get install -y --no-install-recommends apt-utils apt-transport-https
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update -y
RUN ACCEPT_EULA=Y apt-get -y install msodbcsql17
RUN ACCEPT_EULA=Y apt-get -y install mssql-tools
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN /bin/bash -c "source ~/.bashrc"
RUN apt-get install unixodbc-dev
RUN pip install -r requirements.txt
EXPOSE 4040
CMD ["newrelic-admin","run-program","gunicorn", "-c", "gunicorn_config.py", "main:app"]
That error usually indicates a problem with the package repository on the server side (you can test from other client machines/networks to be sure). If you can report it to someone at Microsoft, it usually gets fixed pretty quickly and you can try again after that.
I used Dockerfile successfully built a container. However, my code doesn't work in the container. It does work if I install all the packages manually. I'm assuming I messed up something that cause docker didn't install the packages properly. So, I want to check whether python package is installed or not in Docker container. What is the best way to check it?
The Dockerfile I used:
# Update the sources list
RUN sudo apt-get update
# Install basic applications
RUN sudo apt-get install -y tar git curl nano wget dialog net-tools build-essential
# First install ZeroMQ
RUN sudo apt-get install -y libzmq-dev
# Install libevent
RUN sudo apt-get install -y libevent-dev
# Install Python and Basic Python Tools
RUN sudo apt-get install -y python python-dev python-setuptools
RUN sudo apt-get install -y python-pip
# Add the current directory to the container
ADD . /root/code
# Get pip to download and install requirements:
RUN sudo pip install -r /root/code/requirements.txt
# Expose ports
EXPOSE 80 4242
# Define working directory.
WORKDIR /root/code
# Start the tcp server.
CMD python app.py
The requirements.txt I used:
gevent==1.0.1
greenlet==0.4.5
msgpack-python==0.4.2
pyzmq==13.1.0
wsgiref==0.1.2
zerorpc==0.4.4
I figured out.
docker exec <container ID> pip list