How to run pdfkit from_file in a Docker container - python-3.x

The following is my code for Docker:
FROM python:3.6.2-jessie
## Prepare apt-get:
RUN echo "debconf debconf/frontend select Noninteractive" | debconf-set-selections && \
apt-get update -qy && \
apt-get upgrade -qy && \
apt-get clean autoclean && \
apt-get install wkhtmltopdf -y && \
apt-get autoremove -y && \
apt-get install python3-setuptools -qy &&\
apt-get install python3-dev -qy && \
apt-get install python3-pip -qy && \
apt-get install build-essential -qy && \
apt-get -y install openssh-client -qy && \
apt-get clean
RUN pip3 install --upgrade pip
RUN pip3 install pandas
RUN pip3 install psycopg2==2.7.3.2
RUN pip3 install pdfkit
When I run following code,
docker run my_image python3 pdfkit.py
I get the following error:
OSError: wkhtmltopdf exited with non-zero code -6. error: The switch
--viewport-size, is not support using unpatched qt, and will be ignored.The switch --disable-smart-shrinking, is not support using
unpatched qt, and will be ignored.QXcbConnection: Could not connect to
display

Try the following:
RUN curl -L#o wk.tar.xz https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz \
&& tar xf wk.tar.xz \
&& cp wkhtmltox/bin/wkhtmltopdf /usr/bin \
&& cp wkhtmltox/bin/wkhtmltoimage /usr/bin \
&& rm wk.tar.xz \
&& rm -r wkhtmltox
Rather than installing directly using apt-get install wkhtmltopdf -y.

Related

Install postgresclient/sqlserver odbc drivers in dockerfile

I'm trying to install postgres odbc driver to connect with different external databases with pyodbc
My app receives credentials from any database of type mysql, sqlserver, postgresql, etc. And I'm having problems installing the drivers.
This is my docker file:
FROM python:3.10.9-bullseye
WORKDIR /code
ENV FLASK_APP app.py
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
RUN apt-get update
RUN apt-get install -y openjdk-17-jdk
#Mysql driver
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& curl https://packages.microsoft.com/config/debian/11/prod.list \
> /etc/apt/sources.list.d/mssql-release.list \
&& apt-get install -y --no-install-recommends \
locales \
apt-transport-https \
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& locale-gen \
&& apt-get update \
&& apt-get -y --no-install-recommends install unixodbc-dev libodbc1\
&& ACCEPT_EULA=Y apt-get -y --no-install-recommends install msodbcsql18
RUN sed -i -E 's/(CipherString\s*=\s*DEFAULT#SECLEVEL=)2/\11/' /etc/ssl/openssl.cnf
ENV ACCEPT_EULA=Y
RUN apt-get update -y && apt-get update \
&& apt-get install -y --no-install-recommends curl gcc g++ gnupg unixodbc-dev
#Postgresql
RUN apt-get update \
&& apt-get install -y libsasl2-modules-gssapi-mit libsasl2-modules
#Postgresql unicode
RUN apt-get install -y postgresql
RUN apt-get install -y odbc-postgresql
COPY . .
CMD ["flask", "run", "--debugger", "--reload", "--host=0.0.0.0"]
When I try to connecto with postgres database I got the error:
pyodbc.OperationalError: ('08001', '[08001] [unixODBC]could not
connect to server: No such file or directory\n\tIs the server running
locally and accepting\n\tconnections on Unix domain socket
"/var/run/postgresql/.s.PGSQL.5432"?\n (101) (SQLDriverConnect)')
When I connect with sql server database, I can extract info, but when I try to send info to the database I got this error:
TCP Provider: Error code 0x2746
I'm trying to set the openSSL to 1.0, and that allow me to extract info from sql servers database, but no send it with postgres, even the psql console is not installed :c
I'm having struggling with this drivers for some days. If anyone can help me, I'll be very greatful

Getting critical vulnerability after adding some modules to Dockerfile

`
FROM php:8.1-apache
RUN apt-get update
...
...
RUN docker-php-ext-install mysqli pdo_mysql && docker-php-ext-enable mysqli pdo_mysql
**RUN docker-php-ext-install exif && docker-php-ext-enable exif
RUN apt-get update && apt-get install -y libmagickwand-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
# install imagick
# Version is not officially released https://pecl.php.net/get/imagick but following works for PHP 8
RUN mkdir -p /usr/src/php/ext/imagick; \
curl -fsSL https://github.com/Imagick/imagick/archive/06116aa24b76edaf6b1693198f79e6c295eda8a9.tar.gz | tar xvz -C "/usr/src/php/ext/imagick" --strip 1; \
docker-php-ext-install imagick;
#install some base extensions
RUN apt-get update && apt-get install -y \
zlib1g-dev \
libzip-dev
RUN docker-php-ext-install zip
#gd
#RUN docker-php-ext-install gd && docker-php-ext-enable gd
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
&& docker-php-ext-install gd
#intl
RUN apt-get -y update \
&& apt-get install -y libicu-dev \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl**
RUN a2enmod rewrite
`
Once the docker image is build and push to ECR, I'm getting the 1 critical on Vulnerability part, this happens after adding the modules into the Dockerfile. Can anyone help me to reduce the size and which image to use.

Azure CLI in a Docker Container

I have an Ubuntu 18.04 Docker image that I need Azure CLI installed in. For a Docker image, it seems the preferred way is to use pip, however, I have other pip Azure libraries needed in the container that overlap with the CLI install and get blown away because Azure CLI requires older versions; then making it so I can't run my python scripts.
I have tried to use the script installer but that hasn't worked and errored out because I believe the install is interactive.
The last option I can find is the manual apt install, though I am not sure this is a correct way nor do I have a good idea of how to replicate that in a Dockerfile.
Is there a preferred/good way of getting Azure CLI in a container not using pip?
FROM ubuntu:18.04
RUN apt-get update && apt-get -y upgrade && \
apt-get -f -y install curl python3-pip python-pip && \
pip3 install --upgrade pip && \
pip2 install --upgrade pip && \
pip3 install azure-storage-blob==12.3.0 & \\
pip3 install azure-cli
I have a preference to use the package manager to install dependencies, it's why I will do something like that:
Add base dependencies for https repostory and curl
Add the gpg key and repository for the CLI
Add the CLI
This is the Dockerfile with thoses steps:
FROM ubuntu:18.04
RUN apt-get update && apt-get -y upgrade && \
apt-get -f -y install curl apt-transport-https lsb-release gnupg python3-pip python-pip && \
curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.asc.gpg && \
CLI_REPO=$(lsb_release -cs) && \
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ ${CLI_REPO} main" \
> /etc/apt/sources.list.d/azure-cli.list && \
apt-get update && \
apt-get install -y azure-cli && \
rm -rf /var/lib/apt/lists/*
In addition, I clean up the apt cache by removing /var/lib/apt/lists. Tt reduces the image size, since the apt cache is not stored in a layer.
See: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt#option-1-install-with-one-command
RUN curl -LsS https://aka.ms/InstallAzureCLIDeb | bash && rm -rf /var/lib/apt/lists/*

yum in dockerfile - There are no enabled repos

I am having issues with installing python3 with yum in dockerfile. I did look on internet, I did try few things, not working. Its just small thing but not able to figure it out. When I try to build below docker file I do get error . I get error at line -
RUN yum install -y oracle-epel-release-el7
There are no enabled repos.
Run "yum repolist all" to see the repos you have.
You can enable repos with yum-config-manager --enable <repo>
The docker file is below.
FROM openjdk:13-jdk-slim
ARG MAVEN_VERSION=3.6.3
ARG USER_HOME_DIR="/root"
ARG SHA=c35a1803a6e70a126e80b2b3ae33eed961f83ed74d18fcd16909b2d44d7dada3203f1ffe726c17ef8dcca2dcaa9fca676987befeadc9b9f759967a8cb77181c0
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
# Install prerequisites
RUN apt-get update && apt-get install -y curl
RUN apt-get update && apt-get install -y yum
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
&& curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
&& echo "${SHA} /tmp/apache-maven.tar.gz" | sha512sum -c - \
&& tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
&& rm -f /tmp/apache-maven.tar.gz \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
# Install Python 3.6
RUN yum install -y oracle-epel-release-el7
RUN yum install -y python36
# Install AWS CLI
RUN pip3 install awscli
CMD ["/bin/bash"]
Why mix apt and yum? You're already using apt-get, just use it to install your python too:
apt-get install python3.6

Docker(compose) installing nodejs broke npm

I need to use a container with nginx and nodejs, so I take the nginx container and install the node:
FROM nginx
ENV DEBIAN_FRONTEND noninteractive
WORKDIR /usr/src/app
VOLUME /usr/src/app
RUN apt-get update && \
apt-get install -y apt-utils && \
apt-get install -y --no-install-recommends curl sudo wget nano && \
curl -sL https://deb.nodesource.com/setup_6.x | bash - && \
apt-get install -y nodejs git build-essential && \
whereis npm && \
npm install grunt grunt-cli bower -g && \
whereis returnme nothing npm:, and npm install... crash the build proccess. so Where ir my mistake, is there a bug or anything? btw I'm using latest docker-compose and Docker version 17.03.1-ce, build c6d412e
Update 1: It is not a dupe of this question, I'm only using one RUN line
FROM nginx
RUN \
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections && \
apt-get update && \
apt-get install -y apt-utils && \
apt-get upgrade -y && \
apt-get update --fix-missing && \
apt-get install -y curl sudo wget nano git build-essential
# Install NodeJS
RUN \
wget https://deb.nodesource.com/setup_6.x && \
chmod +x setup_6.x && \
./setup_6.x && \
apt-get install -y nodejs && \
npm install grunt grunt-cli

Resources