Disable user prompt while building a custom Dockerfile image - docker

I'm trying to avoid the user prompt pending while building a Dockerfile image.
docker build .
This is the actual screenshot while building the image:
This is the Dockerfile
FROM ubuntu:latest
LABEL mantainer="mrk088"
LABEL description="Arachni Docker image"
RUN apt-get update
RUN apt-get install -y build-essential curl libcurl4 libcurl4-openssl-dev ruby-full gem
RUN gem update --system
RUN gem install arachni
# Run Arachni Web UI
CMD chmod +x /opt/arachni-ui-web/bin/arachni && /opt/arachni-ui-web/bin/./arachni
EXPOSE 8080/tcp
ENTRYPOINT ["/bin/echo", "Running Arachni Web UI..."]
Does anyone knows how do to disable it?

You need to tell debian that you're in a non-interactive setting.
DEBIAN_FRONTEND=noninteractive apt-get -y update
DEBIAN_FRONTEND=noninteractive apt-get -y build-essential curl libcurl4 libcurl4-openssl-dev ruby-full gem
Also added -y to apt-get so that it doesn't ask for confirmation.

Related

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"]

Cannot install php, apache and postgres on ubuntu base image in dockerfile

I started studying docker recently and wanted to install php, apache and postgres in a ubuntu base image. But cannot run it after build.
Here is my Dockerfile
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get -qq -y install curl
RUN apt-get -y install apache2
RUN apt-get -y install php7.0
RUN apt-get -y install libapache2-mod-php7.0
RUN apt-get -y install php7.0-mysql
RUN apt-get -y install php7.0-pgsql
RUN apt-get -y install php7.0-gd
RUN apt-get -y install php-pear
RUN apt-get -y install php7.0-curl
COPY . /var/www/html
EXPOSE 80
Can you please help me?
Thanks.
there are several issues here. First of all, I have the impression that you're mixing up docker and virtual machines. For this I suggest to go and read what are the differences.
Concerning your question, the problem is that the base image (ubuntu:16.04) has CMD bash (or something similar, I really didn't check) and therefore php is not considered.
In order to start apache, you should append the following:
CMD . /etc/apache2/envvars && /usr/sbin/apache2ctl -DFOREGROUND
Anyway, I'd suggest you give a check to the php official image.

How to install kerberos client in docker?

I am trying to create Docker image by next Dockerfile. It must to install Kerberos client.
Dockerfile:
FROM node:latest
RUN export DEBIAN_FRONTEND=noninteractive
RUN apt-get -qq update
RUN apt-get -qq install krb5-user libpam-krb5
RUN apt-get -qq clean
COPY / ./
EXPOSE 3000
CMD ["npm", "start"]
Next command RUN apt-get -qq install krb5-user libpam-krb5 from Dockerfile ask me to enter the value to interactive prompt which looks like:
Default Kerberos version 5 realm:
The point is that the command does not terminate even if I write value and press enter. Whats wrong and how to fix it?
You need a -y parameter for apt
FROM node:latest
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -qq update && \
apt-get -yqq install krb5-user libpam-krb5 && \
apt-get -yqq clean
COPY / ./
EXPOSE 3000
CMD ["npm", "start"]
And remember, that each RUN directive create one additional layer in the image, so it will be nice to reduce the amount of this directives.

Dockerfile error: /bin/sh: 1: [“python”,: not found

here is my Dockerfile tried to build:
FROM ubuntu:latest
# install flask server
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY app.py /
RUN pip install flask
# install ruby
RUN \
apt-get install -y ruby ruby-dev ruby-bundler && \
rm -rf /var/lib/apt/lists/*
# install lua
RUN apt-get update -y && apt-get install -y luajit luarocks
# Define default command.
CMD [“python”, “app.py”]
However, it shown up with error
/bin/sh: 1: [“python”,: not found
I have no idea why this happened. Could someone please help me with it?
Make sure to use the right CMD syntax with "", not “”:
CMD ["executable","param1","param2"] (exec form, this is the preferred form)

Resources