How to convert an Ubuntu package/repository to Alpine in a Dockerfile? - docker

Currently I have this Dockerfile
FROM ubuntu:18.04
# https://github.com/tesseract-shadow/tesseract-ocr-re
RUN apt-get update && apt-get install -y software-properties-common && add-apt-repository -y ppa:alex-p/tesseract-ocr
RUN apt-get update && apt-get install -y tesseract-ocr-all
RUN apt-get install -y git build-essential cmake
RUN apt-get install -y ffmpeg
# Install Node and NPM
RUN apt-get install nodejs -y && apt-get install npm -y
The size of the image is too big so I searched for alternatives and found about Alpine.
I'm stuck with this one
FROM alpine
RUN apk add --update ffmpeg cmake nodejs npm
Looking at the aline edge repository, I can't seem to find tesseract-ocr-all and no idea how to do apt-get install -y software-properties-common && add-apt-repository -y ppa:alex-p/tesseract-ocr in alpine.
Are there any resources that can help me through this? Should I make my own Alpine image for those packages/repositories?

The alpine package name is tesseract-ocr, you can check here the releases or alpine repository.
FROM alpine
RUN apk add --update --no-cache ffmpeg cmake nodejs npm tesseract-ocr
If you are interested in the beta version you may check here.
Always try to add --no-cache option allows to not cache the index locally, which keeps containers small.

Related

Docker Compose: Apt-utils installation problem

I am trying to build a new image in Docker Compose but the following problem occurs
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/a/apt/apt-utils_2.4.7_amd64.deb 404 Not Found [IP: ]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
The command '/bin/sh -c apt-get install -y apt-utils' returned a non-zero code: 100
ERROR: Service 'nginx-service' failed to build : Build failed
In my Dockerfile I'm running: RUN apt-get install -y apt-utils and with --fix-missing.
None of the related questions or other solutions helped me and I've been stuck for quite a while. What am I missing?
Thanks!
EDIT: The whole Dockerfile
FROM ubuntu:latest
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y nginx
RUN apt-get clean
RUN apt-get install -y curl
RUN apt-get install -y unzip
RUN apt-get install -y wget
RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata
RUN apt-get install -y php php-xml php-curl php-fpm php-mysql
RUN apt-get install -y apt-utils --fix-missing
RUN apt-get install -y php-zip --fix-missing
RUN apt-get install -y php-gd --fix-missing
RUN apt-get install -y mysql-server
RUN curl -sS https://getcomposer.org/installer -o composer-setup.php
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN apt-get install -y nano
RUN apt-get install -y mc
RUN apt-get install -y systemctl
RUN systemctl start nginx.service
usually , when we are building a new image, we use update then install like this
RUN apt-get update && apt-get install -y apt-utils
This will update apt source list and will make the package available to install.
Addibg this to your Dockerfile should fix the issue.
If you want to install many at once you can add the packages like the following :
RUN apt-get update && apt-get install -y \
bzr \
cvs \
git \
mercurial \
subversion \
Building the image like this:
docker-compose build --no-cache
worked for me

Error running a docker image, unable to locate package

I have this Dockerfile:
FROM debian:latest
RUN apt-get update &&
apt-get -y install curl &&
apt-get install -y apt-transport-https
RUN curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | bash
RUN apt-get -qq -y install sysbench git make gcc unzip wget lua5.1 lua5.1-dev &&
apt-get clean
RUN wget https://luarocks.org/releases/luarocks-2.4.3.tar.gz && tar zxpf luarocks-2.4.3.tar.gz && cd luarocks-2.4.3 && ./configure && make bootstrap
And when I try to create the image with it, at some point of the process I get this error:
Step 5/6 : RUN apt-get -qq -y install sysbench git make gcc unzip wget lua5.1 lua5.1-dev && apt-get clean
—> Running in 4787766a3d2c
E: Unable to locate package sysbench
The command ‘/bin/sh -c apt-get -qq -y install sysbench git make gcc unzip wget lua5.1 lua5.1-dev && apt-get clean’ returned a non-zero code: 100
Anyone knows where the problem could be?
Thanks
There is a reported bug about sysbench on aarch, ( which is the target arm processor that rpi uses).
Try to follow the suggestion in:
https://github.com/akopytov/sysbench/issues/298

Docker build stops on software-properties-common when run with `apt update`

I have 2 dockerfiles:
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y \
software-properties-common \
python3
FROM ubuntu:20.04
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN apt-get update && apt-get install -y \
python3
The thing is: when I run the first of them (with docker build) the build process hangs on:
The software-properties-common package is asking me about the geographical area - I cannot provide any input, it is not allowed when building images, I suppose.
However, when I build the second dockerfile, this problem does not occur. I'm curious - why is that?
Add the following line in your Dockerfile and build again.
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata
I found that running
ln -fs /usr/share/zoneinfo/UTC /etc/localtime
before setting DEBIAN_FRONTEND=noninteractive worked for me. (You'd want to replace the bit after zoneinfo with whatever is applicable for you.)
If you need it to be set dynamically, [this answer] (https://stackoverflow.com/a/63153978/1995015) suggests calling out to a website that can provide that.

Docker image size is coming up to 1.7 G for Ubuntu with Python packages

Following is my Dockerfile :-
FROM ubuntu:18.04 AS builder
RUN apt update -y
RUN apt install python3.8 -y && apt install python3-pip -y
RUN apt install build-essential automake pkg-config libtool libffi-dev libgmp-dev -y
RUN apt install libsecp256k1-dev -y
RUN apt install openjdk-8-jre -y
RUN apt install git -y
RUN apt install libkrb5-dev -y
RUN apt install vim -y
RUN mkdir /opt/app
RUN chown -R root:root /opt/app
COPY ["requirements.txt","/opt/app/requirements.txt"]
SHELL ["/bin/bash", "-c"]
WORKDIR /opt/app
RUN pip3 install -r requirements.txt && apt-get -y clean all
RUN mkdir /opt/app/
RUN chown -R root:root /opt/app/
RUN cd /opt/app/
RUN git clone -b master https://bitbucket.org/heroes/test.git
CMD ["bash","/opt/app/bin/connect.sh"]
Docker image is generating with an image file size of 1.7G. I need to have OpenJDK hence cannot use a standard python package as a base package. When I perform docker history , I can see 2 or 3 layers (installing packages above like Python3.8, OpenJDK and libsecp256k1-dev) taking up to 400MB to 500MB in size. Ubuntu as a base image takes only 64 MB however rest of size is taking by my dockerfile layers.
I believe I need to re-write the dockerfile in order to reduce the file size which I did but nothing happened concrete.
Please assist me on reducing the image less than 1 GB at least.
[Update]
Below is my updated Dockerfile:-
FROM ubuntu:18.04 AS builder
WORKDIR /opt/app
COPY requirements.txt /opt/app/aws/requirements.txt
RUN mkdir -p /opt/app/aws \
&& apt-get update -yq \
&& apt-get install -y python3.8 python3-pip openjdk-8-jre -yq && apt-get -y clean all \
&& chown -R root:root /opt/app && cd /opt/app/aws && pip3 install -r requirements.txt
FROM alpine
COPY --from=builder /opt/app /opt/app
SHELL ["/bin/bash", "-c"]
CMD ["bash","/opt/app/aws/bin/connector/connect.sh"]
Screenshot of image size:-
After removing unwanted libraries like git, etc and using the multi-stage build, the image is now approx 1.7 GB which I believe is a lot. Any suggestion to improve this?
You have multiple issues going on.
First, each of your RUN apt install is increasing your image size, you should have them all in the same RUN stage, and at the end of the stage, delete all cached apt files.
Second, you're installing unnecessary stuff. Why would you need vim and git for instance? Why are you installing build-essential and other build-related stuff if you're not building anything?
Third, it seems you tried to do a multi-stage build but ended up adding everything to the same image. Read up on python multi-stage builds.
If we consider best practices instead of multiple RUN use single RUN.
For example
RUN apt-get update -yq \
&& apt-get install -y python3-dev build-essential -yq \
&& apt-get install curl -yq \
&& pip install -r requirements.txt \
&& apt-get purge -y --auto-remove gcc python3-dev build-essential
you can use multistage builds if you don't require git in your final image you can remove in final stage
Also if possible you can use alpine version also.
Try disabling recommended packages of APT with --no-install-recommends, you can read more about it from here.
Now the image is smaller:
FROM ubuntu:18.04 AS builder
RUN apt update -y
RUN apt install python3-pip -y
RUN apt install build-essential automake pkg-config libtool libffi-dev libgmp-dev -y
RUN apt install libsecp256k1-dev -y
RUN apt install openjdk-8-jre-headless -y
RUN apt install git -y
RUN apt install libkrb5-dev -y
RUN apt install vim -y
RUN mkdir /opt/app
RUN chown -R root:root /opt/app
COPY ["requirements.txt","/opt/app/requirements.txt"]
SHELL ["/bin/bash", "-c"]
WORKDIR /opt/app
RUN pip3 install -r requirements.txt && apt-get -y clean all
RUN mkdir /opt/app/
RUN chown -R root:root /opt/app/
RUN cd /opt/app/
RUN git clone -b master https://bitbucket.org/heroes/test.git
CMD ["bash","/opt/app/bin/connect.sh"]

How can I install ffmpeg to my docker image

I have setup a docker image in my Windows 10 Machine.
Can you please tell me how can I install ffmpeg to that docker image?
apt-get install ffmpeg
As of 2019, this seems to work, just fine on Docker.
Dockerfile
RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get install -y ffmpeg
In your dockerfile you can write this command to add required repo, update your repository and then install ffmpeg.
Though I am not sure if this library still exist I just modified this Link for Docker you can follow same rules to install another package.
RUN set -x \
&& add-apt-repository ppa:mc3man/trusty-media \
&& apt-get update \
&& apt-get dist-upgrade \
&& apt-get install -y --no-install-recommends \
ffmpeg \
If you stop with select of geographic area on Ubuntu 18.04 or above, you can install it by specifying ENV DEBIAN_FRONTEND=noninteractive as shown below.
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y ffmpeg
As of July 2022, this works for Dockerfile, well at least it worked for me.
RUN apt-get -y update && apt-get -y upgrade && apt-get install -y --no-install-recommends ffmpeg
Just to let the community know.

Resources