Errors after reducing layers of a docker images - docker

I am getting multiple errors when I reduce layer in the following image file.
configure: error: in /root/xdebug': configure: error: no acceptable C compiler found in $PATH See config.log' for more details
Following Original file is not giving me any errors. it's only when I make the changes to the file. I think it has something to do with permissions and the way I'm adding steps.
FROM amazonlinux
ARG DOCKER_TYPE
ENV DOCKER_TYPE=$DOCKER_TYPE
ARG UID
RUN yum update -y
RUN yum install sudo -y
RUN sudo yum install git -y
RUN sudo amazon-linux-extras install php7.2 -y
RUN sudo yum install php-mbstring -y
RUN sudo yum install php-openssl -y
RUN sudo yum install php-pdo_mysql -y
RUN sudo yum install php-simplexml -y
RUN sudo yum install php-soap -y
RUN sudo yum install php-spl -y
RUN sudo yum install php-xsl -y
RUN sudo yum install php-zip -y
RUN sudo yum install php-libxml -y
RUN sudo yum install php-intl -y
RUN sudo yum install php-iconv -y
RUN sudo yum install php-hash -y
RUN sudo yum install php-gd -y
RUN sudo yum install php-dom -y
RUN sudo yum install php-curl -y
RUN sudo yum install php-ctype -y
RUN sudo yum install php-bcmath -y
RUN sudo yum install php-devel -y
RUN sudo yum groupinstall "Development tools" -y
# Xdebug
RUN cd /root/; git clone https://github.com/xdebug/xdebug.git; cd /root/xdebug/; ./rebuild.sh
Updated version
FROM amazonlinux
ARG DOCKER_TYPE
ENV DOCKER_TYPE=$DOCKER_TYPE
ARG UID
RUN yum update -y
RUN yum install sudo -y && sudo yum install -y \
git \
amazon-linux-extras install php7.2 \
php-mbstring \
php-openssl \
php-pdo_mysql \
php-simplexml \
php-soap \
php-spl \
php-xsl \
php-zip \
php-libxml \
php-intl \
php-iconv \
php-hash \
php-gd \
php-dom \
php-curl \
php-ctype \
php-bcmath \
php-devel \
groupinstall "Development tools"
# Xdebug
RUN cd /root/; git clone https://github.com/xdebug/xdebug.git; cd /root/xdebug/; ./rebuild.sh

You're replacing the line
RUN sudo amazon-linux-extras install php7.2
with an argument to yum install.
That's apparently something different.
You can probably fix it by adding && after git and starting a new sudo yum install for the following packages.
Indentation which clearly shows where a new command is started and where you just add more arguments to a command would help readability a lot.

Your updated dockerfile should look something like this:
FROM amazonlinux
ARG DOCKER_TYPE
ENV DOCKER_TYPE=$DOCKER_TYPE
ARG UID
RUN yum update -y && \
yum install sudo -y && \
sudo yum install git -y && \
sudo amazon-linux-extras install php7.2 -y && \
sudo yum install php-mbstring -y && \
sudo yum install php-openssl -y && \
sudo yum install php-pdo_mysql -y && \
sudo yum install php-simplexml -y && \
sudo yum install php-soap -y && \
sudo yum install php-spl -y && \
sudo yum install php-xsl -y && \
sudo yum install php-zip -y && \
sudo yum install php-libxml -y && \
sudo yum install php-intl -y && \
sudo yum install php-iconv -y && \
sudo yum install php-hash -y && \
sudo yum install php-gd -y && \
sudo yum install php-dom -y && \
sudo yum install php-curl -y && \
sudo yum install php-ctype -y && \
sudo yum install php-bcmath -y && \
sudo yum install php-devel -y && \
sudo yum groupinstall "Development tools" -y && \
sudo yum clean all
# Xdebug
RUN cd /root/; git clone https://github.com/xdebug/xdebug.git; cd /root/xdebug/; ./rebuild.sh
To change multiple "RUN" instructions you need to run them with && between them. The "\" character marks that the instruction continues in the next line.
I've also added
yum clean all
at the end of this single RUN instruction to keep your image layers smaller.

Related

Issue compiling Dockerfile on MacOS(apple Sillicon)

This is my first time to use Docker
I build a Dockerfile and use the Vscode remote container to open folder in Container.
When I run this Dockerfile on Windows 11. It does not have any problem
But When I run it on MacOS(apple Sillicon). It have error.
after I step by step to check the Dockerfile.
I find that if I install g++multilib or libc6-dev-i386, it will get error.
I do not have any idea about why?
Dockerfile:
FROM ubuntu:18.04
RUN apt update \
&& apt-get -y install gcc g++ python \
&& apt-get -y install python-dev \
&& apt-get -y install qt4-dev-tools libqt4-dev \
&& apt-get -y install mercurial \
&& apt-get -y install bzr \
&& apt-get -y install cmake libc6-dev \
&& apt-get -y install gdb valgrind \
&& apt-get -y install flex bison libfl-dev \
&& apt-get -y install tcpdump \
&& apt-get -y install sqlite sqlite3 libsqlite3-dev \
&& apt-get -y install gsl-bin libgslcblas0 \
&& apt-get -y install libxml2 libxml2-dev \
&& apt-get -y install libgtk2.0-0 libgtk2.0-dev \
&& apt-get -y install vtun lxc \
&& apt -y install git \
&& apt -y install npm \
&& apt-get -y install g++-multilib libc6-dev-i386
devcontainer.json:
{
"name": "802.11ah ns-3 simulation",
"dockerFile": "Dockerfile",
"appPort": 3000,
"extensions": ["dbaeumer.vscode-eslint"],
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
}
}
error information: https://i.stack.imgur.com/ZE04I.jpg
You dont have specified the architetture of Ubuntu container in docker file. Apple silicon have ARM architecture, not all image are compatibile.

How to run a bash script that takes multiple user intactive inputs , as part of dockerfile

I have the below dockerfile that needs to run a owasp bash file for its intallation.
This .sh file needs multiple inputs(like 1, Y, enter) from the user for the completion of installation.
How do I provide these inputs from dockerfile or is there a way to skip these inputs and continue the installation.
This dockerfile is a part of the docker-compose.
Below is thew dockerfile
FROM ubuntu:20.04
RUN apt-get update && apt-get upgrade -y && apt-get clean
RUN apt-get install python3-pip -y
RUN apt-get install vim -y
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Indian
# Install OpenJDK-8
RUN apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean;
# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
RUN apt-get install wget -y && \
apt-get install unzip -y && \
apt-get install zip -y
RUN mkdir /home/owasp
RUN wget -c https://github.com/zaproxy/zaproxy/releases/download/v2.11.0/ZAP_2_11_0_unix.sh -P /home/owasp
RUN chmod u+x /home/owasp/ZAP_2_11_0_unix.sh
RUN ./home/owasp/ZAP_2_11_0_unix.sh
Use the Linux Package : https://github.com/zaproxy/zaproxy/releases/download/v2.11.0/ZAP_2.11.0_Linux.tar.gz
That has the same contents but is just a gziped tar file :)
Full list of ZAP downloads available is on https://www.zaproxy.org/download/
Or you can always extend our docker images https://www.zaproxy.org/docs/docker/
To provide input for command use some input generator and pipe it with your command.
Typical example is using command yes which provides endless stream of "y" on output:
RUN yes|./own-shell-scrpit.sh
You can run printf 'y\n1abc\nxxx' and pipe it. "\n" in printf states for newline (or enter).
I would suggest adding a ENTRYPOINT so it by default will invoke your bash script, but it gives the flexibily to the end user to pass different arguments. See the official docs. Keep in mind the CMD provided in a Dockerfile is a default command. You override it by passing any other value.
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Indian
RUN apt-get update && apt-get upgrade -y && apt-get clean
RUN apt-get install python3-pip -y
RUN apt-get install vim -y
# Install OpenJDK-8
RUN apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean;
# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
RUN apt-get install wget -y && \
apt-get install unzip -y && \
apt-get install zip -y
RUN mkdir /home/owasp
RUN wget -c https://github.com/zaproxy/zaproxy/releases/download/v2.11.0/ZAP_2_11_0_unix.sh -P /home/owasp
RUN chmod u+x /home/owasp/ZAP_2_11_0_unix.sh
ENTRYPOINT ./home/owasp/ZAP_2_11_0_unix.sh
CMD ['--some', '--default', '--args']
You can even choose to pass default flags on build. So your script will then always run with default flags you provided on docker build --build-args DEFAULT_PARAMS=--foo, unless you override it:
ARGS DEFAULT_PARAMS
FROM ubuntu:20.04
ENV DEFAULT_PARAMS=${DEFAULT_PARAMS}
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Indian
RUN apt-get update && apt-get upgrade -y && apt-get clean
RUN apt-get install python3-pip -y
RUN apt-get install vim -y
# Install OpenJDK-8
RUN apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean;
# Fix certificate issues
RUN apt-get update && \
apt-get install ca-certificates-java && \
apt-get clean && \
update-ca-certificates -f
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
RUN apt-get install wget -y && \
apt-get install unzip -y && \
apt-get install zip -y
RUN mkdir /home/owasp
RUN wget -c https://github.com/zaproxy/zaproxy/releases/download/v2.11.0/ZAP_2_11_0_unix.sh -P /home/owasp
RUN chmod u+x /home/owasp/ZAP_2_11_0_unix.sh
ENTRYPOINT ./home/owasp/ZAP_2_11_0_unix.sh
CMD ${DEFAULT_PARAMS}

ssh-keygen: command not found in Docker

I am trying to run this below command inside a docker container
(centos 7 as the base image)
ssh-keygen -t rsa -N ""
and I get this error:
ssh-keygen: command not found
And this is the Dockerfile I used to build the container
FROM centos:7
ENV VER "0.12.9"
RUN yum update -y && yum install wget -y && yum install unzip -y
RUN yum install epel-release -y && yum install ansible -y
RUN wget https://releases.hashicorp.com/terraform/${VER}/terraform_${VER}_linux_amd64.zip
RUN unzip terraform_${VER}_linux_amd64.zip
RUN mv terraform /usr/local/bin/
RUN rm -rf terraform_${VER}_linux_amd64.zip
Can someone help me, Please?
ssh-keygen is command provided by OpenSSH, you need to install it.
Add yum install openssh-clients -y to your Dockerfile.
FROM centos:7
ENV VER "0.12.9"
RUN yum update -y && yum install wget -y && yum install unzip -y
RUN yum install epel-release -y && yum install ansible -y && yum install openssh-clients -y
RUN wget https://releases.hashicorp.com/terraform/${VER}/terraform_${VER}_linux_amd64.zip
RUN unzip terraform_${VER}_linux_amd64.zip
RUN mv terraform /usr/local/bin/
RUN rm -rf terraform_${VER}_linux_amd64.zip

Install from source in Docker

I need to install graph-tool from source, so I add in my Dockerfile this:
FROM ubuntu:18.04
RUN git clone https://git.skewed.de/count0/graph-tool.git
RUN cd graph-tool && ./configure && make && make install
as it written here.
When I try to build my Docker-compose I catch a error:
/bin/sh: 1: ./configure: not found
What am I doing wrong? Thanks!
ADDED Full Dockerfile:
FROM ubuntu:16.04
ENV LANG C.UTF-8
ENV PYTHONUNBUFFERED 1
ENV C_FORCE_ROOT true
# Install dependencies
RUN apt-get update \
&& apt-get install -y git \
&& apt-get install -y python3-pip python3-dev \
&& apt-get install -y binutils libproj-dev gdal-bin \
&& cd /usr/local/bin \
&& ln -s /usr/bin/python3 python \
&& pip3 install --upgrade pip
RUN git clone https://git.skewed.de/count0/graph-tool.git
RUN apt-get update && apt-get install -y gcc
RUN apt-get update && apt-get install -y libboost-all-dev
RUN apt update && apt install -y --no-install-recommends \
make \
build-essential \
g++
RUN cd graph-tool && ./configure && make && make install
# Project specific setups
RUN mkdir /code
WORKDIR /code
ADD . /code
RUN pip3 install -r requirements.txt
You need to run autogen.sh first, it will generate configure file
P.S. Make sure you install libtool
apt-get install libtool
You have to install the prerequisites first.
RUN apt update && apt install -y --no-install-recommends \
make \
build-essential \
g++ \
....
Don't forget to clean up and remove temp/unnecessary files!

Docker 's Error: libselinux conflicts with fakesystemd

I'm building docker image with a Dockerfile:
FROM centos:centos7.1.1503
MAINTAINER foo <foo#bar.com>
ENV TZ "Asia/Shanghai"
ENV TERM xterm
RUN \
yum update -y && \
yum install -y epel-release &&\
yum update -y && \
yum install -y curl wget tar bzip2 unzip vim-enhanced passwd sudo yum-utils hostname net-tools rsync man && \
yum install -y gcc gcc-c++ git make automake cmake patch logrotate python-devel libpng-devel libjpeg-devel && \
yum install -y pwgen python-pip && \
yum clean all
and it show the error as below:
Error: libselinux conflicts with fakesystemd-1-17.el7.centos.noarch
If I change FROM centos:centos7.1.1503 to FROM centos:centos7,all will work fine. So ,what should I do to using centos7.1.1503
My Linux Distribution is Ubuntu 16.04.1 LTS and my docker version is 1.12.6.
Try running this inside the container you create, before any installation is made:
yum swap -y fakesystemd systemd && yum clean all
yum update -y && yum clean all
Or inside a Dockerfile at the begining before the first RUN you have tipped:
RUN yum swap -y fakesystemd systemd && yum clean all \
&& yum update -y && yum clean all
Hope was useful!

Resources