Docker Debian install fails - docker

I have a Dockerfile that works, but if I add any new dependencies to the apt-get install command, it fails. For example, this works:
FROM debian:stable
RUN apt-get update
RUN apt-get install -y \
python \
...
apache2
But if I try this, it fails:
FROM debian:stable
RUN apt-get update
RUN apt-get install -y \
python \
...
apache2
python-mysqldb
I can replace python-mysqldb with anything else, git-core, for example, and it will still fail with the same error message:
Unable to correct missing packages.
E: Failed to fetch http://security.debian.org/pool/updates/main/l/linux/linux-libc-dev_3.16.7-ckt11-1+deb8u5_amd64.deb 404 Not Found [IP: 149.20.20.6 80]
E: Aborting install.
Any thoughts on why adding a new dependency causes the failure and how to fix it?

I've found that you need to join the update & install command into the same RUN block.
eg:
RUN apt-get update \
&& apt-get install -y \
python \
...
apache2 \
python-mysqldb
According to this post describing the issue
By default, Docker cache your commands to reduce time spent building
images. Unless there was any change before such commands (or at the
same line).
Meanwhile, I notice that the AWS examples separate them, as you have them. So I dunno if it works different there. Maybe they disable the cache by default.

Related

laravel-with-docker-example project fails to build

I am trying to run below project with docker.
https://github.com/kyleferguson/laravel-with-docker-example
which has the below docker file.
FROM php:7-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client \
&& docker-php-ext-install mcrypt pdo_mysql
WORKDIR /var/www
When i run the "docker-compose up" after running the "composer install".
I get below errors.
executor failed running [/bin/sh -c apt-get update && apt-get install
-y libmcrypt-dev mariadb-client && docker-php-ext-install mcrypt pdo_mysql]: exit code: 1 ERROR: Service 'app' failed to build
Any idea on how to fix this?
Note:
I already tried replacing mariadb-client with mysql-client and default-my-client, still the same issue.
You have a couple problems here, which is why switching to mariadb didn't work on its own.
One way to make it more clear what the problem is, is to bash into a container created from your base image and run the commands manually.
docker run -it php:7-fpm bash
From there if you run each install individually you'll see where you are failing:
# apt-get install -y mysql-client
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package mysql-client
Either add a repo that provides mysql, or use mariadb.
# docker-php-ext-install mcrypt
error: /usr/src/php/ext/mcrypt does not exist
mcrypt was removed in php 7.2 so you'll need to use pecl to install it, if you really need it.
Unless you're running a very old version of Laravel, you shouldn't need mcrypt.

issue in creating docker image from docker file

Created a Docker file in oreder to install Tomcat server from Unix as bashe os
My Dockerfile:
FROM ubuntu
RUN apt-get update && apt-get upgrade -y #to update os
RUN apt-get dist-upgrade
RUN apt-get install build-essential
RUN apt-get install openjdk-8-jdk # to install java 8
RUN apt-get wget -y #to install wget package
RUN apt-get wget https://mirrors.estointernet.in/apache/tomcat/tomcat-9/v9.0.37/bin/apache-tomcat-9.0.37.tar.gz #to download tomcat
RUN tar -xvzf apache-tomcat-9.0.37 # unzipping the tomcat
RUN mkdir tomcat # craeting tomacat directory
RUN cp apache-tomcat-9.0.37/* tomcat # copying tomact files to tomact directory
Command to create Docker Image from Docker file:
docker build -t [img name] -f [file name] .
On execution, while installing java package am getting like this:
'''After this operation, 242 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y'''
You are getting the prompt because the command is awaiting user input for whether or not to install a package. The -y flag you're using for a few of them (like wget) allows bash to assume a yes. Add this flag to all your installation commands.
By the way, there's quite a few potential issues with the Dockerfile you posted.
For example, you have RUN apt-get wget ...
Are you sure that is what you want to do, and not just RUN wget ...? Unless wget is a command that apt-get takes, which it isn't, it will cause unexpected behavior.
You also seem to be missing the command to start the Tomcat server, which can make it so that nothing happens when you attempt to run the image.
I think you should add DEBIAN_FRONTEND=noninteractive when running the apt-get commands, something like this:
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install build-essential -y
Also, it's considered bad practice to use multiple RUN steps which could be consolidated into one. More about Dockerfile best practices can be found here.

Install Java runtime in Debian based docker image

I am trying to install the java runtime in a Debian based docker image (mcr.microsoft.com/dotnet/core/sdk:3.1-buster). According to various howtos this should be possible by running
RUN apt update
RUN apt-get install openjdk-11-jre
The latter command comes back with
E: Unable to locate package openjdk-11-jre
However according to https://packages.debian.org/buster/openjdk-11-jre the package does exist. What am I doing wrong?
Unsure from which image your are pulling. I used slim, Dockerfile.
from debian:buster-slim
ENV DEBIAN_FRONTEND=noninteractive
RUN mkdir -p /usr/share/man/man1 /usr/share/man/man2
RUN apt-get update && \
apt-get install -y --no-install-recommends \
openjdk-11-jre
# Prints installed java version, just for checking
RUN java --version
NOTE: If you don't run the mkdir -p /usr/share/man/man1 /usr/share/man/man2 you'll run into dependency problems with ca-certificates, openjdk-11-jre-headless etc. I've been using this fix provided by community, haven't really checked the permanent fix.

Dockerized Dotnet Core 2.1 throws Gdip exception when using Select.HtmlToPdf.NetCore

I am using Select.HtmlToPdf.NetCore(18.3.0) to convert Html to pdf in Dotnetcore 2.1. It is perfectly working in local environment but when hosted with Docker it throws an error saying,
{"fileName":"System.TypeInitializationException: The type initializer
for 'Gdip' threw an exception. ---> System.DllNotFoundException:
Unable to load shared library 'libdl' or one of its dependencies. In
order to help diagnose loading problems, consider setting the LD_DEBUG
environment variable: liblibdl: cannot open shared object file: No
such file or directory\n at Interop.Libdl.dlopen(String fileName,
Int32 flag)\n at
System.Drawing.SafeNativeMethods.Gdip.LoadNativeLibrary()\n at
System.Drawing.SafeNativeMethods.Gdip..cctor()\n --- End of inner
exception stack trace ---\n at
System.Drawing.SafeNativeMethods.Gdip.GdipNewPrivateFontCollection(IntPtr&
fontCollection)\n at SelectPdf.Lib.ᡜ..ctor()\n at
SelectPdf.Lib.៞..ctor()\n at SelectPdf.Lib.៞..ctor(ᡏ A_0, ᠝ A_1)\n
at SelectPdf.HtmlToPdf.ᜁ(String A_0, String A_1, String A_2, String
A_3, Boolean A_4)\n at SelectPdf.HtmlToPdf.ConvertHtmlString(String
htmlString)
I have tried by adding these set of lines in Dockerfile, but still having the same error.
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-get install -y libgdiplus
RUN ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll
WORKDIR /app
EXPOSE 80
I know It is an old question but I encountered this problem lately and I would like to share with my solution.
Select.HtmlToPdf.NetCore do not work on linux
Just do not. If you already have generated string with html I would advise you to find this nuget: Haukcode.DinkToPdf
To find some tutorials just google DinkToPdf. Haukcode is just updated and more docker friendly version.
some dockerfile stuff:
FROM microsoft/aspnetcore:2.0.0 as Base
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-get install -y libgdiplus
RUN apt-get install -y libc6-dev
RUN ln -s /usr/lib/libgdiplus.so/usr/lib/gdiplus.dll
...
I hope it will help someone :)
this worked for me.
I'm running a Debian server, using System.Drawing.Common 4.7.0
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev \
&& rm -rf /var/lib/apt/lists/*
You need to install libc6-dev in your Docker container. You can install libc6-dev by running the following command:
RUN apt-get install -y libc6-dev
Let me know how that goes.
I was facing the same problem too using iTextSharp 5.5.13.1 and the way I've solved is combine #Frederik Carlier's solution in my Dockerfile:
RUN apt-get update && apt-get -y install libxml2 libgdiplus libc6-dev
After that, i've restarted Rancher Container and Rancher User Stack and it works fine.
(Runtime used: FROM microsoft/dotnet:2.2-aspnetcore-runtime)

Docker commands require keyboard interaction

I'm trying to create a Docker image for ripping CDs (using abcde).
Here's the relevant portion of the Dockerfile:
FROM ubuntu:17.10
MAINTAINER Graham Nicholls <graham#rockcons.co.uk>
RUN apt update && apt -y install eject vim ruby abcde
...
Unfortunately, the package "abcde" pulls in a mail client (not sure which), and apt tries to configure that by asking what type of mail connection to configure (smarthost/relay etc).
When docker runs, it's not appearing to read from stdin, so I can't redirect into the docker process.
I've tried using --nodeps with apt (and replacing apt with apt-get); unfortunately --nodeps seems no-longer to be a supported option and returns:
E: Command line option --nodeps is not understood in combination with the other options
Someone has suggested using expect in response to a similar question, which I'd rather avoid. This seems to be a "difficult to google" problem - I can't find anything.
So, is there a way of passing in the answer to the config in apt, or of preventing apt from pulling in a mail client, which would be better - I'm not planning in sending updates to cddb.
The typical template to install apt packages in a docker container looks like:
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
eject \
vim \
ruby \
abcde \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
Running it with the "noninteractive" value removes any prompts. You don't want to set that as an ENV since that would also impact any interactive commands you run inside the container.
You also want to cleanup the package database when finished to reduce the layer size and avoid reusing a stale cached package database in a later step.
The no-install-recommends option will reduce the number of packages installed by only installing the required dependencies, not the additional recommended packages. This cuts the size of the root filesystem down by half for me.
If you need to pass a non-default configuration to a package, then use debconf. First run you install somewhere interactively and enter the options you want to save. Install debconf-utils. Then run:
debconf-get-selections | grep "${package_name}"
to view all the options you configured for that package. You can then pipe these options to debconf-set-selections in your container before running your install, e.g.:
RUN echo "postfix postfix/main_mailer_type select No configuration" \
| debconf-set-selections \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
....
or save your selections to a file that you copy in:
COPY debconf-selections /
RUN debconf-set-selections </debconf-selections \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
....

Resources