stdint.h not found in Alpine docker image - docker

I am getting a error: no include path in which to search for stdint.h error message when building a docker image from alpine:edge, that leads to other errors like unknown type name 'uint32_t' and failure when compiling a program.
As far as I understand, stdint.h is part of the C++ standard library and should be present, unless there is something broken within alpine:edge, which I don't think will be the case.
My docker image is the following:
FROM alpine:edge
RUN apk update && apk add \
git \
make \
gcc \
python3 \
ldc \
&& git clone --recursive https://github.com/lomereiter/sambamba.git \
&& cd sambamba \
&& make \
&& mv sambamba /usr/local/bin/ \
&& cd ../.. \
&& rm -r sambamba
WORKDIR /wd
ENTRYPOINT ["/usr/local/bin/sambamba"]
Note that the image alpine:edge is necessary, because the ldc package is only available on it. How to fix this? Why isn't stdint.h found?

To successfully compile Sambamba, you need some additional packages:
g++ (for the C++ compiler and includes)
zlib
zlib-dev (for the zlib Header files)
Overall, this modified Dockerfile should do the trick:
FROM alpine:edge
RUN apk update && apk add \
git \
make \
gcc \
g++ \
zlib \
zlib-dev \
python3 \
ldc \
&& git clone --recursive https://github.com/lomereiter/sambamba.git \
&& cd sambamba \
&& make \
&& mv sambamba /usr/local/bin/ \
&& cd ../.. \
&& rm -r sambamba
WORKDIR /wd
ENTRYPOINT ["/usr/local/bin/sambamba"]

Related

Failed to get jdk (jdk-8u301-linux-x64.tar.gz) on alpine:3.8

I'm trying to build the image which was built in the past but failing this time as it is failing to download Oracle JDK, it downloads the tar with just a 4 KB file.
I have referred this Docker alpine + oracle java: cannot find java already and tried with the latest version of glibc but no luck.
I'm though able to install the lower version than jdk-8u201.
Any suggestion is appreciated! I have to go with alpine:3.8 only.
FROM alpine:3.8
RUN apk upgrade --update && \
apk add --update curl ca-certificates bash && \
for pkg in glibc-2.23-r1 glibc-bin-2.23-r1 glibc-i18n-2.23-r1; do curl -sSL https://github.com/andyshinn/alpine-pkg-glibc/releases/download/2.23-r1/${pkg}.apk -o /tmp/${pkg}.apk; done && \
apk add --allow-untrusted /tmp/*.apk && \
rm -v /tmp/*.apk && \
mkdir -p /opt/springboot/apps/ && \
( /usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 C.UTF-8 || true ) && \
echo "export LANG=C.UTF-8" > /etc/profile.d/locale.sh && \
/usr/glibc-compat/sbin/ldconfig /lib /usr/glibc-compat/lib && \
curl -jksSLH "Cookie: oraclelicense=accept-securebackup-cookie" -o /tmp/java.tar.gz \
https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz && \
gunzip /tmp/java.tar.gz

Docker image with v8 compiled reached almost 5GB. What am I doing wrong?

Sorry, this is my first time using docker so there may be chances that I'm using the wrong term. Basically, I need to use this image as the base of our project, however, when I try to build our project using docker-compose it takes quite a long time build which I suspect is because of the file size of the image. Is there anything I can do to reduce the file size down to 500MB? Here is what I have in the image's docker file.
FROM php:7.2-apache-buster
ENV V8_VERSION=7.4.288.21
RUN apt-get update -y --fix-missing && apt-get upgrade -y;
# Install v8js (see https://github.com/phpv8/v8js/blob/php7/README.Linux.md)
RUN apt-get install -y --no-install-recommends \
libtinfo5 libtinfo-dev \
build-essential \
curl \
git \
libglib2.0-dev \
libxml2 \
python \
patchelf \
&& cd /tmp \
\
&& git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --progress --verbose \
&& export PATH="$PATH:/tmp/depot_tools" \
\
&& fetch v8 \
&& cd v8 \
&& git checkout $V8_VERSION \
&& gclient sync \
\
&& tools/dev/v8gen.py -vv x64.release -- is_component_build=true use_custom_libcxx=false
RUN export PATH="$PATH:/tmp/depot_tools" \
&& cd /tmp/v8 \
&& ninja -C out.gn/x64.release/ \
&& mkdir -p /opt/v8/lib && mkdir -p /opt/v8/include \
&& cp out.gn/x64.release/lib*.so out.gn/x64.release/*_blob.bin out.gn/x64.release/icudtl.dat /opt/v8/lib/ \
&& cp -R include/* /opt/v8/include/ \
&& apt-get install patchelf \
&& for A in /opt/v8/lib/*.so; do patchelf --set-rpath '$ORIGIN' $A;done
# Install php-v8js
RUN cd /tmp \
&& git clone https://github.com/phpv8/v8js.git \
&& cd v8js \
&& phpize \
&& ./configure --with-v8js=/opt/v8 LDFLAGS="-lstdc++" \
&& make \
&& make test \
&& make install
RUN docker-php-ext-enable v8js
As #david-maze pointed me to right direction which is to use multi-stage build I managed to reduce the file size from almost 5GB down to 470MB by tracing all the files I need to copy to another build. Here is what I got
FROM php:7.2-apache-buster
COPY --from=BASE_PHP /opt /opt
COPY --from=BASE_PHP /usr/local/etc/php/conf.d/docker-php-ext-v8js.ini /usr/local/etc/php/conf.d/
COPY --from=BASE_PHP /usr/local/lib/php/extensions/no-debug-non-zts-20170718 /usr/local/lib/php/extensions/no-debug-non-zts-20170718
Thank you so much

Is there a more efficient way to dockerize Luarocks?

I am trying to build a lean alpine docker container for unit testing Lua in Google Cloud Build.
It runs fine, but takes about 30 - 50 seconds to build. When I run busted and luacheck, it only takes a few seconds for each. Any thoughts on how I could optimize this build process?
I was using wget and then switched to git. I added curl and unzip since luarocks expects it and openssl for one of luacheck's dependencies. Are there different dependencies I could/should use?
FROM alpine
ENV LUA_VERSION 5.1
RUN apk update
RUN apk add lua${LUA_VERSION}
RUN apk add lua${LUA_VERSION}-dev
RUN apk add bash build-base curl git openssl unzip
RUN cd /tmp && \
git clone https://github.com/keplerproject/luarocks.git && \
cd luarocks && \
sh ./configure && \
make build install && \
cd && \
rm -rf /tmp/luarocks
RUN luarocks install busted
RUN luarocks install luacheck
RUN luarocks install luacov
You can try this
Dockerfile
FROM alpine:3.12
# Set environment
ENV LUA_VERSION=5.1.5 \
LUAROCKS_VERSION=3.4.0
# Install dependency packages
RUN set -xe && \
apk add --no-cache --virtual .build-deps \
curl \
gcc \
g++ \
libc-dev \
make \
readline-dev \
&& \
apk add --no-cache \
readline \
&& \
# Install Lua
wget http://www.lua.org/ftp/lua-${LUA_VERSION}.tar.gz && \
tar zxf lua-${LUA_VERSION}.tar.gz && rm -f lua-${LUA_VERSION}.tar.gz && \
cd lua-${LUA_VERSION} && \
make -j $(getconf _NPROCESSORS_ONLN) linux && make install && \
cd / && rm -rf lua-${LUA_VERSION} && \
# Install LuaRocks
wget https://luarocks.org/releases/luarocks-${LUAROCKS_VERSION}.tar.gz && \
tar zxf luarocks-${LUAROCKS_VERSION}.tar.gz && rm -f luarocks-${LUAROCKS_VERSION}.tar.gz && \
cd luarocks-${LUAROCKS_VERSION} && \
./configure && \
make -j $(getconf _NPROCESSORS_ONLN) build && make install && \
cd / && rm -rf luarocks-${LUAROCKS_VERSION} && \
# Remove all build deps
apk del .build-deps && \
# Test
lua -v && luarocks
COPY docker-entrypoint.sh /usr/local/bin
docker-entrypoint.sh
#!/bin/sh
set -e
buildDepsApk="
curl
libc-dev
gcc
wget
"
pm='unknown'
if [ -e /lib/apk/db/installed ]; then
pm='apk'
fi
if [ "$pm" = 'apk' ]; then
apk add --no-cache ${buildDepsApk}
fi
luarocks install $#
if [ "$pm" = 'apk' ]; then
apk del ${buildDepsApk}
fi
You don't have to build luarocks. You can just install the package using,
RUN apk add luarocks

Docker image Size increases if I remove few lines of code

I'm trying to reduce the docker image size, but Dockerfile is being weird.
I concatenate the RUN command to reduce the size of the image. When I build the below Dockerfile it creates only 235MB.
FROM nginx:alpine
RUN apk add --no-cache --virtual .build-deps \
gcc \
libc-dev \
make \
openssl \
pcre-dev \
zlib-dev \
linux-headers \
curl \
gnupg \
libxslt-dev \
gd-dev \
perl-dev \
&& apk add --no-cache --virtual .libmodsecurity-deps \
pcre-dev \
libxml2-dev \
git \
libtool \
automake \
autoconf \
g++ \
flex \
bison \
yajl-dev \
git \
# Add runtime dependencies that should not be removed
&& apk add --no-cache \
doxygen \
geoip \
geoip-dev \
yajl \
libstdc++ \
sed \
# Installing ModSec Library version 3
&& echo "Installing ModSec Library" \
&& git clone -b v3/master --single-branch https://github.com/SpiderLabs/ModSecurity /opt/ModSecurity \
&& cd /opt/ModSecurity \
&& git submodule init \
&& git submodule update \
&& ./build.sh \
&& ./configure && make && make install \
&& echo "Finished Installing ModSec Library" \
# Installing ModSec - Nginx connector
&& cd /opt \
&& echo 'Installing ModSec - Nginx connector' \
&& git clone --depth 1 https://github.com/SpiderLabs/ModSecurity-nginx.git \
&& wget http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz \
&& tar zxvf nginx-$NGINX_VERSION.tar.gz \
# Adding Nginx Connector Module
&& cd /opt/nginx-$NGINX_VERSION \
&& ./configure --with-compat --add-dynamic-module=../ModSecurity-nginx \
&& make modules \
&& cp objs/ngx_http_modsecurity_module.so /etc/nginx/modules \
&& echo "Finished Installing ModSec - Nginx connector" \
# Begin installing ModSec OWASP Rules
&& echo "Begin installing ModSec OWASP Rules" \
&& mkdir /etc/nginx/modsec \
&& wget -P /etc/nginx/modsec/ https://raw.githubusercontent.com/SpiderLabs/ModSecurity/v3/master/modsecurity.conf-recommended \
&& mv /etc/nginx/modsec/modsecurity.conf-recommended /etc/nginx/modsec/modsecurity.conf \
&& sed -i 's/SecRuleEngine DetectionOnly/SecRuleEngine On/' /etc/nginx/modsec/modsecurity.conf \
# Fetching owasp-modsecurity-crs
&& cd /opt \
&& git clone -b v3.0/master https://github.com/SpiderLabs/owasp-modsecurity-crs \
&& mv owasp-modsecurity-crs/ /usr/local/ \
&& cp /usr/local/owasp-modsecurity-crs/crs-setup.conf.example /usr/local/owasp-modsecurity-crs/crs-setup.conf \
# Creating modsec file
&& echo 'Creating modsec file' \
&& echo -e '# From https://github.com/SpiderLabs/ModSecurity/blob/master/\n \
# modsecurity.conf-recommended\n \
# Edit to set SecRuleEngine On\n \
Include "/etc/nginx/modsec/modsecurity.conf"\n \
# OWASP CRS v3 rules\n \
Include "/usr/local/owasp-modsecurity-crs/crs-setup.conf"\n \
Include "/usr/local/owasp-modsecurity-crs/rules/*.conf"'\
>>/etc/nginx/modsec/main.conf \
&& chown nginx:nginx /etc/nginx/modsec/main.conf \
# Removing old Nginx conf files
&& rm -fr /etc/nginx/conf.d/ \
&& rm -fr /etc/nginx/nginx.conf \
&& chown -R nginx:nginx /usr/share/nginx \
# delete uneeded and clean up
&& apk del .build-deps \
&& apk del .libmodsecurity-deps \
&& rm -fr ModSecurity \
&& rm -fr ModSecurity-nginx \
&& rm -fr nginx-$NGINX_VERSION.tar.gz \
&& rm -fr nginx-$NGINX_VERSION
COPY conf/nginx.conf /etc/nginx
COPY conf/conf.d /etc/nginx/conf.d
COPY errors /usr/share/nginx/errors
WORKDIR /usr/share/nginx/html
CMD nginx -g 'daemon off;'
EXPOSE 80
I have seen the docker history imagedId it shows that this RUN command has an increased size around 855MB. Anybody Understand why it is behaving weird?
Any thoughts would be much helpful, its is hard to debug building the image everytime.
I tried building in both ways and found not much difference.
Most of the disk space is consumed by /opt/ModSecurity
Initially it was 74MB after git clone.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
oldimage latest 924a8d4f941e 11 minutes ago 867MB
newimage latest d1ca029927c2 About an hour ago 867MB
nginx alpine ebe2c7c61055 6 days ago 18MB
However after building the complete build - it has grown to ~650MB.
$ du -sh *
639.7M ModSecurity
408.0K ModSecurity-nginx
7.5M nginx-1.13.12
996.0K nginx-1.13.12.tar.gz

Installing miniconda on alpine linux fails

I have been attempting to install miniconda on an Alpine linux docker image. The minimal "working" example of my failure can be reproduced with Docker as follows:
docker run --rm -it alpine sh
/ # apk update && apk add ca-certificates wget && update-ca-certificates
/ # wget https://repo.continuum.io/miniconda/Miniconda3-4.3.27-Linux-x86_64.sh -O ~/miniconda.sh
/ # sh miniconda.sh -b
PREFIX=/root/miniconda3
installing: python-3.6.2-h02fb82a_12 ...
/root/miniconda.sh: line 361: /root/miniconda3/pkgs/python-3.6.2-h02fb82a_12/bin/python: not found
The file that it looks for is there, though:
/ # ls /root/miniconda3/pkgs/python-3.6.2-h02fb82a_12/bin/python
/root/miniconda3/pkgs/python-3.6.2-h02fb82a_12/bin/python
I would appreciate some insight on this error. I have little idea of what to try next
According to #VladFrolov, anaconda's python is linked to glibc, which isn't available in alpine. For more details about how he built an alpine image with conda, look at https://github.com/frol/docker-alpine-miniconda3
PS: Looks like #VladFrolov now maintains miniconda3:alpine official image https://github.com/ContinuumIO/docker-images/blob/master/miniconda3/alpine/Dockerfile ( Thx for pointing out #rpanai )
You can add this before running the ./miniconda.sh -b:
apk --update add \
bash \
curl \
wget \
ca-certificates \
libstdc++ \
glib \
&& wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-node-bower/master/sgerrand.rsa.pub \
&& curl -L "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.23-r3/glibc-2.23-r3.apk" -o glibc.apk \
&& apk add glibc.apk \
&& curl -L "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.23-r3/glibc-bin-2.23-r3.apk" -o glibc-bin.apk \
&& apk add glibc-bin.apk \
&& curl -L "https://github.com/andyshinn/alpine-pkg-glibc/releases/download/2.25-r0/glibc-i18n-2.25-r0.apk" -o glibc-i18n.apk \
&& apk add --allow-untrusted glibc-i18n.apk \
&& /usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8 \
&& /usr/glibc-compat/sbin/ldconfig /lib /usr/glibc/usr/lib \
&& rm -rf glibc*apk /var/cache/apk/*

Resources