Composer installation with curl not working in Docker - docker

Below is the Dockerfile I have for creating a docker image. It was working so great but today I tried to build image in --no-cache mode since than I am having the issue. The error message detail is given bellow.
I repeat, it was working fine but now runs into error. Tried searching few solutions but nothing worked.
In particular this command is not working curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
FROM alpine:edge
MAINTAINER SamratShakya <samrat.shakya#nepallink.net>
# Install packages
RUN apk --update add \
curl \
php7 \
php7-dom \
php7-fpm \
php7-mbstring \
php7-mcrypt \
php7-opcache \
php7-pdo \
php7-pdo_mysql \
php7-pdo_pgsql \
php7-mysqli \
php7-xml \
php7-simplexml \
php7-common \
php-simplexml \
php7-phar \
php7-openssl \
php7-json \
php7-ctype \
php7-session \
php7-tokenizer \
php7-xmlwriter \
nodejs \
git \
ca-certificates \
nginx \
wget \
libcurl \
php7-curl \
supervisor \
&& rm -rf /var/cache/apk/*
RUN curl -sS https://getcomposer.org/installer | php \
--install-dir=/usr/bin --filename=composer
This is the error message I get in jenkins logs.
Error message:
Step 4/21 : RUN curl -sS https://getcomposer.org/installer | php --install-dir=/usr/bin --filename=composer
---> Running in f79b6610ae38
[91mError relocating /usr/bin/php: explicit_bzero: symbol not found
[0m[91mcurl: (23) Failed writing body (0 != 16133)
[0mThe command '/bin/sh -c curl -sS https://getcomposer.org/installer | php --install-dir=/usr/bin --filename=composer' returned a non-zero code: 127
PROBLEM IN IMAGE BUILD !!
Build step 'Execute shell' marked build as failure
Finished: FAILURE

Try again with:
RUN curl -sS https://getcomposer.org/installer | \
php -- --install-dir=/usr/bin --filename=composer

Nothing worked for me so as a workaround, What I did is added the composer as multistage image. I added composer separately and copied it to my alpine image as bellow.
FROM composer:1.5.1 AS composer
FROM alpine:edge
#copying composer from another image and making it work
COPY --from=php-composer /usr/bin/composer /usr/bin/composer
RUN ln -s /usr/bin/php7 /usr/bin/php
Regarding the issue I had. I am not able to extract the exact cause

Related

How to upload large docker images to google container registry?

I'm creating a lap image from this (https://github.com/ulsmith/alpine-apache-php7) and in my application, I have a 2.5 GB folder of images the image is built successfully but when I try to push it to google container registry it doesn't work due to large size and sometimes server timeout and that will be like after a minimum of 20 min. I get the error of image after 15 mins or more and before that the google cloud SDK is showing nothing.
Here is the command I am using: gcloud builds submit --tag us.gcr.io/[project-id]/test:v1
I checked crcmod and it is enabled.
This is my Dockerfile:+
FROM alpine:edge
MAINTAINER Paul Smith <pa.ulsmith.net>
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
RUN apk update && apk upgrade && apk add \
bash apache2 php7-apache2 curl ca-certificates openssl openssh git php7 php7-phar php7-json php7-iconv php7-openssl tzdata openntpd nano
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
RUN apk add \
php7-ftp \
php7-xdebug \
php7-mcrypt \
php7-mbstring \
php7-soap \
php7-gmp \
php7-pdo_odbc \
php7-dom \
php7-pdo \
php7-zip \
php7-mysqli \
php7-sqlite3 \
php7-pdo_pgsql \
php7-bcmath \
php7-gd \
php7-odbc \
php7-pdo_mysql \
php7-pdo_sqlite \
php7-gettext \
php7-xml \
php7-xmlreader \
php7-xmlwriter \
php7-tokenizer \
php7-xmlrpc \
php7-bz2 \
php7-pdo_dblib \
php7-curl \
php7-ctype \
php7-session \
php7-redis \
php7-exif \
php7-intl \
php7-fileinfo \
php7-ldap \
php7-apcu
RUN apk add php7-simplexml
RUN cp /usr/bin/php7 /usr/bin/php \
&& rm -f /var/cache/apk/*
RUN sed -i "s/#LoadModule\ rewrite_module/LoadModule\ rewrite_module/" /etc/apache2/httpd.conf \
&& sed -i "s/#LoadModule\ session_module/LoadModule\ session_module/" /etc/apache2/httpd.conf \
&& sed -i "s/#LoadModule\ session_cookie_module/LoadModule\ session_cookie_module/" /etc/apache2/httpd.conf \
&& sed -i "s/#LoadModule\ session_crypto_module/LoadModule\ session_crypto_module/" /etc/apache2/httpd.conf \
&& sed -i "s/#LoadModule\ deflate_module/LoadModule\ deflate_module/" /etc/apache2/httpd.conf \
&& sed -i "s#^DocumentRoot \".*#DocumentRoot \"/app/public\"#g" /etc/apache2/httpd.conf \
&& sed -i "s#/var/www/localhost/htdocs#/app/public#" /etc/apache2/httpd.conf \
&& printf "\n<Directory \"/app/public\">\n\tAllowOverride All\n</Directory>\n" >> /etc/apache2/httpd.conf
ENV PHP_ALLOW_URL_INCLUDE=On
RUN mkdir /app && mkdir /app/public && chown -R apache:apache /app && chmod -R 755 /app && mkdir bootstrap
COPY app/ /app/public/
ADD start.sh /bootstrap/
RUN chmod +x /bootstrap/start.sh
EXPOSE 80
ENTRYPOINT ["/bootstrap/start.sh"]
Is there a better way to push large images?
Please contact us with the un-redacted image at gcr-contact#google.com
In general (this may not be an issue for you), the problem with large images is that the short-lived access tokens you receive via our normal token exchange will result in failed uploads. You're going to have to explore JSON key authentication in order to enable those very long sessions when uploading your images to GCR
Also to note that Container Registry does not support Docker chunked uploads. Some container image tools support uploading large container images with either chunked uploads or a single monolithic upload. You must use monolithic uploads when you push container images to Container Registry.
If you are pushing a large image to GCR a much quicker way would be to:
Spin up a GCP VM instance
Upload your Dockerfile (and any relevant files needed for the build)
Build the container and push to GCR from there

Docker chrome selenium java openjdk:8 to Alpine

I have a Dockerfile that already works in openjdk:8 but I am trying to convert it to alpine. It is giving me some troubles. The application was made in Java and uses Selenium. This is my current code:
FROM openjdk:8-jdk-alpine
RUN apk update \
&& apk fetch gnupg \
&& apk add --virtual \
curl wget xvfb unzip gnupg \
&& gpg --list-keys
ARG CHROME_DRIVER_VERSION=85.0.4183.87
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
&& apk update \
&& apk add google-chrome-stable \
&& apk cache clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& wget https://chromedriver.storage.googleapis.com/${CHROME_DRIVER_VERSION}/chromedriver_linux64.zip \
&& unzip chromedriver_linux64.zip \
&& mv chromedriver /usr/bin/chromedriver \
&& chown root:root /usr/bin/chromedriver \
&& chmod +x /usr/bin/chromedriver
EXPOSE 42052
.
.
.
I tried to add gnupg like I found in here:
Docker: Using apt-key with alpine image
But it does not work, I just get an error: /bin/sh: gpg: not found
If I removed it, I just get the issue with apt-key that is not found. What is the alternative in alpine or what changes do I have to do to my docker file to work again.
Thanks in advance
Apparently the Chrome .deb file won't work on Alpine. So it needs Chromium to work. If you are already using the ChromeDriver in the Java code it will work without making any changes like in my case.
FROM openjdk:8-jdk-alpine
RUN apk update && apk add --no-cache bash \
alsa-lib \
at-spi2-atk \
atk \
cairo \
cups-libs \
dbus-libs \
eudev-libs \
expat \
flac \
gdk-pixbuf \
glib \
libgcc \
libjpeg-turbo \
libpng \
libwebp \
libx11 \
libxcomposite \
libxdamage \
libxext \
libxfixes \
tzdata \
libexif \
udev \
xvfb \
zlib-dev \
chromium \
chromium-chromedriver \
&& rm -rf /var/cache/apk/* \
/usr/share/man \
/tmp/*
RUN mkdir -p /data && adduser -D chrome \
&& chown -R chrome:chrome /data
USER chrome
.
.
.
If you are going to add create folders and/or add files like in my case, just add USER root to work
It will work the same as the openjdk:8 version.
Actually alpine version in answer post to correct work has to add in code:
chromeOptions.setBinary("/usr/bin/chromium-browser");

PHP 7.1 Docker build will not compile with pgsql

I am using the polinux/httpd:centos repo to run Apache and PHP 7.1. The build seems to go ok. There are a few warnings related to keys, but none related to php or pgsql. The build completes successfully, but when I ssh into the container the module is not listed (php -m) and there's no extension config file in php.d.
I verified it is listed in the Dockerfile multiple times.
I can install php71-php-pgsql manually after starting the container, but then I can't restart Apache without restarting the container.
I've tried moving yum install php71-php-pgsql to the end of the Dockerfile as a separate RUN command (in addition to the original), but it reports it has already been installed, yet when I ssh into the container its not listed in the modules and no config, as mentioned above.
When I rebuild a container I stop and remove it, then run build with the no-cache option.
I'm stumped...
The Dockerfile is quite long, but I can post if that would be helpful.
Thanks.
UPDATE: Dockerfile per request...
FROM polinux/httpd:centos
ENV \
NVM_DIR="/usr/local/nvm" \
NODE_VERSION="9.2.0" \
GIT_VERSION="2.15.0" \
PHP_VERSION="71"
ADD mariadb.repo /etc/yum.repos.d/mariadb.repo
RUN \
rpm --rebuilddb && yum clean all && rm -rf /var/cache/yum && \
yum update -y && \
yum install -y \
wget \
patch \
bzip2 \
unzip \
make \
openssh-clients \
git \
MariaDB-client && \
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm && \
yum install -y \
php${PHP_VERSION}-php \
php${PHP_VERSION}-php-bcmath \
php${PHP_VERSION}-php-cli \
php${PHP_VERSION}-php-common \
php${PHP_VERSION}-php-devel \
php${PHP_VERSION}-php-fpm \
php${PHP_VERSION}-php-gd \
php${PHP_VERSION}-php-gmp \
php${PHP_VERSION}-php-intl \
php${PHP_VERSION}-php-json \
php${PHP_VERSION}-php-mbstring \
php${PHP_VERSION}-php-mcrypt \
php${PHP_VERSION}-php-mysqlnd \
php${PHP_VERSION}-php-pgsql \
php${PHP_VERSION}-php-opcache \
php${PHP_VERSION}-php-pdo \
php${PHP_VERSION}-php-pear \
php${PHP_VERSION}-php-process \
php${PHP_VERSION}-php-pspell \
php${PHP_VERSION}-php-xml \
php${PHP_VERSION}-php-pecl-imagick \
php${PHP_VERSION}-php-pecl-mysql \
php${PHP_VERSION}-php-pecl-uploadprogress \
php${PHP_VERSION}-php-pecl-uuid \
php${PHP_VERSION}-php-pecl-memcache \
php${PHP_VERSION}-php-pecl-memcached \
php${PHP_VERSION}-php-pecl-redis \
php${PHP_VERSION}-php-pecl-zip && \
ln -sfF /opt/remi/php${PHP_VERSION}/enable /etc/profile.d/php${PHP_VERSION}-paths.sh && \
ln -sfF /opt/remi/php${PHP_VERSION}/root/usr/bin/{pear,pecl,phar,php,php-cgi,php-config,phpize} /usr/local/bin/. && \
mv -f /etc/opt/remi/php${PHP_VERSION}/php.ini /etc/php.ini && ln -s /etc/php.ini /etc/opt/remi/php${PHP_VERSION}/php.ini && \
rm -rf /etc/php.d && mv /etc/opt/remi/php${PHP_VERSION}/php.d /etc/. && ln -s /etc/php.d /etc/opt/remi/php${PHP_VERSION}/php.d && \
yum install -y \
ImageMagick \
GraphicsMagick \
gcc \
gcc-c++ \
libffi-devel \
libpng-devel \
zlib-devel && \
yum install -y ruby ruby-devel && \
echo 'gem: --no-document' > /etc/gemrc && \
gem update --system && \
gem install bundler && \
export PROFILE=/etc/profile.d/nvm.sh && touch $PROFILE && \
curl -sSL https://raw.githubusercontent.com/creationix/nvm/v0.31.2/install.sh | bash && \
source $NVM_DIR/nvm.sh && \
nvm install $NODE_VERSION && \
nvm alias default $NODE_VERSION && \
nvm use default && \
npm install -g \
gulp \
grunt-cli \
bower \
browser-sync && \
echo -e "StrictHostKeyChecking no" >> /etc/ssh/ssh_config && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
chown apache /usr/local/bin/composer && composer --version && \
yum clean all && rm -rf /tmp/yum* && \
sed -i 's|SetHandler application/x-httpd-php|SetHandler "proxy:fcgi://127.0.0.1:9000"|g' /etc/httpd/conf.d/php${PHP_VERSION}-php.conf
ADD container-files /
ENV \
NODE_PATH=$NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules \
PATH=$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
RUN \
mkdir -p /data/tmp/php && \
chmod -R 777 /data/tmp
# Weird issue: For some reason pgsql is not installed above. May be OoO...
Manually installing worked, so adding here at the end.
RUN \
yum install php71-php-pgsql -y
Chalk this up to inexperience...
This turned out to be a problem with how I was referencing images, first when building and then running the instance. I'm still not sure I fully understand, but I think I was running the base container instead of the modified build.
For others that may run into similar problems, the 2 commands that helped me get this working are:
docker build --rm -t local/httpd-php71 .
... and then ...
docker run \
-d \
--name httpd-php71 \
--restart unless-stopped \
--net dockersubnet \
--volume /www:/var/www \
local/httpd-php71
Where 'local/httpd-php71' is my local/custom build. Before I was not using any tag reference in the build command and then I was referencing 'polinux/httpd:centos', the base, in the run command.
Thanks.

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/*

Can't install package on alpine though I can see it in the ui

I was running php7 on alpine without a hitch for the last week till today when I rebuilt my image and now nothing works. I get the errors:
/ # apk add php7
ERROR: unsatisfiable constraints:
php7 (missing):
required by: world[php7]
for every package , extension I was trying to install and that previously worked. Here's the RUN command I was using to setup php7:
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
apk update && \
apk upgrade && \
apk add --update \
php7-mcrypt \
php7-soap \
php7-openssl \
php7-gmp \
php7-pdo_odbc \
php7-json \
php7-dom \
php7-pdo \
php7-zip \
php7-mysqli \
php7-sqlite3 \
php7-pdo_pgsql \
php7-bcmath \
php7-gd \
php7-odbc \
php7-pdo_mysql \
php7-pdo_sqlite \
php7-gettext \
php7-xmlreader \
php7-xmlrpc \
php7-bz2 \
php7-iconv \
php7-pdo_dblib \
php7-curl \
php7-ctype \
php7-fpm
All the above extensions installed flawlessly last week. What I'm I missing?
Proof the packages do exist: https://pkgs.alpinelinux.org/packages?name=php7-*&branch=&repo=&arch=&maintainer=
Package php7 has been moved from the testing to the community repository, so you have to replace http://dl-cdn.alpinelinux.org/alpine/edge/testing with http://dl-cdn.alpinelinux.org/alpine/edge/community.
You should use the official PHP 7 Alpine image on DockerHub.
Then, per the image documentation, use the docker-php-ext-install command in your Dockerfile:
FROM php:7-fpm-alpine
RUN apk update \
&& apk add libmcrypt-dev \
&& docker-php-ext-install mcrypt mysqli pdo_mysql \
&& rm /var/cache/apk/*
This may initially look a little strange, but it works and is the officially supported Docker approach.
We provide the helper scripts docker-php-ext-configure,
docker-php-ext-install, and docker-php-ext-enable to more easily
install PHP extensions.
DockerHub - PHP

Resources