Docker, cannot execute binary file: Exec format error - docker

I have created Dockerfile, when i'm try to run a problem inside my container i'm getting error:
bash: xxx: cannot execute binary file: Exec format error
Dockerfile:
FROM debian:buster-slim
# Set the working directory to /usr/local/bin
WORKDIR /usr/local/bin
# Build container and setup wallet
RUN apt-get update -y && \
apt-get autoremove -y && \
apt-get install wget -y && \
wget https://euno.co/wallet/euno-2.0.2.tar.gz && \
tar zxvf euno-2.0.2.tar.gz && \
rm -rf euno-2.0.2.tar.gz && \
mkdir /root/.eunopay && \
chmod 755 euno*
# change working dir to eunopay folder
WORKDIR /root/.eunopay
# Download bootstrap
RUN wget https://euno.co/bootstrap/euno-bootstrap.tar.gz && \
tar zxvf euno-bootstrap.tar.gz && \
rm -rf euno-bootstrap.tar.gz && \
echo "server=1" >> euno.conf && \
echo "deamon=1" >> euno.conf && \
echo "debug=0" >> euno.conf
WORKDIR /root
ENTRYPOINT [ "/bin/bash", "-l", "-c" ]
Can anyone help me out what's going wrong?

Related

docker-compose.yml - container with exited status on Ubuntu host

My docker-compose.yml:
version: "3.3"
services:
build_and_run_service:
image: myapp:0
build: .
network_mode: host
volumes:
- './bin/cookie:/app/cookie'
- './bin/logs:/app/logs'
- './bin/warehouse:/app/warehouse'
Dockerfile doesn't contain CMD and ENTRYPOINT, so when I execute commands in that order:
docker build --tag myapp:0 .
docker run -d -t myapp:0
docker exec -it <container_id> /bin/bash
It works as expected.
For some reason the container is not working when using docker compose...
Commands order:
docker-compose up -d --build
docker-compose run -d build_and_run_service bash
What's wrong?
Both cases work fine on Windows but not on Ubuntu...
#edit
Dockerfile:
FROM ubuntu:20.04 as runtime
LABEL description="Build and run container - myapp"
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN apt-get install -y nano
RUN apt-get install -y wget
RUN apt-get install -y curl
RUN apt-get install -y make
RUN apt-get install -y build-essential
RUN apt-get install -y tcl zlib1g-dev libssl-dev tk libcurl4-gnutls-dev libexpat1-dev gettext dos2unix
# Compilers
RUN apt-get install -y gcc-10
RUN apt-get install -y g++-10
RUN rm /usr/bin/gcc \
&& ln -s /usr/bin/gcc-10 /usr/bin/gcc
RUN rm /usr/bin/g++ \
&& ln -s /usr/bin/g++-10 /usr/bin/g++
# Postgres dev
RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
RUN wget --no-check-certificate --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN apt-get update
RUN apt-get install -y libpq-dev postgresql-server-dev-13
RUN cd /tmp \
&& wget --no-check-certificate https://www.openssl.org/source/openssl-1.1.1g.tar.gz \
&& tar -zxf openssl-1.1.1g.tar.gz \
&& cd openssl-1.1.1g \
&& ./config \
&& make \
&& make install \
&& rm /usr/bin/openssl \
&& ln -s /usr/local/bin/openssl /usr/bin/openssl \
&& ldconfig
RUN cd /tmp \
&& wget --no-check-certificate https://cmake.org/files/v3.19/cmake-3.19.6-Linux-x86_64.tar.gz \
&& tar -zxf cmake-3.19.6-Linux-x86_64.tar.gz \
&& mv cmake-3.19.6-Linux-x86_64 /usr/local/ \
&& ln -s /usr/local/cmake-3.19.6-Linux-x86_64/bin/cmake /usr/bin/cmake
RUN cd /tmp \
&& wget --no-check-certificate https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.31.0.tar.gz \
&& tar -zxf git-2.31.0.tar.gz \
&& cd git-2.31.0 \
&& make prefix=/usr/local all \
&& make prefix=/usr/local install
RUN cd /tmp \
&& wget --no-check-certificate https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz \
&& tar -zxf boost_1_75_0.tar.gz \
&& cd boost_1_75_0 \
&& ./bootstrap.sh \
&& ./b2 \
&& ./b2 install
VOLUME ["/app/cookie", "/app/logs", "/app/warehouse"]
WORKDIR /app
COPY . /src
RUN cd /src \
&& mkdir build \
&& cd build
# Some building command
## PRIVATE ##
# Removes tmp
RUN cd /tmp \
&& rm -r *

Dockerfile not able to find ionic or cordova after install

I have a Dockerfile for which I'm trying to install ionic and cordova. The installation seems to work without error but I'm not able use them inside the container. The thing is, they are installed globally so I not sure what I'm missing. Any assistance is appreciated.
FROM openjdk:8
MAINTAINER me
# Install Git and dependencies
RUN dpkg --add-architecture i386 \
&& apt-get update \
&& apt-get install -y file git curl zip libncurses5:i386 libstdc++6:i386 zlib1g:i386 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists /var/cache/apt
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get install -y nodejs
RUN mkdir -p /tmp/yarn && \
mkdir -p /opt/yarn/dist && \
cd /tmp/yarn && \
wget -q https://yarnpkg.com/latest.tar.gz && \
tar zvxf latest.tar.gz && \
find /tmp/yarn -maxdepth 2 -mindepth 2 -exec mv {} /opt/yarn/dist/ \; && \
rm -rf /tmp/yarn
RUN ln -sf /opt/yarn/dist/bin/yarn /usr/local/bin/yarn && \
ln -sf /opt/yarn/dist/bin/yarn /usr/local/bin/yarnpkg && \
yarn --version
RUN yarn global add ionic
RUN yarn global add cordova
# Set up environment variables
ENV ANDROID_HOME="/home/user/android-sdk-linux" \
SDK_URL="https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip" \
GRADLE_URL="https://services.gradle.org/distributions/gradle-4.5.1-all.zip"
# Create a non-root user
RUN useradd -m user
USER user
WORKDIR /home/user
# Download Android SDK
RUN mkdir "$ANDROID_HOME" .android \
&& cd "$ANDROID_HOME" \
&& curl -o sdk.zip $SDK_URL \
&& unzip sdk.zip \
&& rm sdk.zip \
&& yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses
# Install Gradle
RUN wget $GRADLE_URL -O gradle.zip \
&& unzip gradle.zip \
&& mv gradle-4.5.1 gradle \
&& rm gradle.zip \
&& mkdir .gradle
ENV PATH="/home/user/gradle/bin:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${PATH}"

Docker multistage build doesn't recognise installed application

FROM some-build:latest as build
COPY / /var/www/html
WORKDIR /var/www/html
RUN cd /var/www/html && composer install
FROM some-build2:latest as run
COPY --from=build /var/www/html /var/www/html
ENV PATH ${HOME}/local/bin:${PATH}:/home/site/wwwroot
RUN cd /var/www/html && \
npm install && \
npm run production
ENTRYPOINT ["/bin/init_container.sh"]
The image run contains an installed npm. Despite this fact, the npm install return the error: /bin/sh: 1: npm: not found
How is this possible? What am I doing wrong?
Edit:
As answer to #BMitch 's comment, when I run the RUN image, in the container the node is on the PATH and I can use it. The path is /root/local/bin. I've attached all the Dockerfiles.
I have 3 docker files:
APP
The one you've already seen before.
RUN
FROM php:7.2.5-apache
MAINTAINER Azure App Services Container Images <appsvc-images#microsoft.com>
COPY apache2.conf /bin/
COPY init_container.sh /bin/
RUN a2enmod rewrite expires include deflate
# install the PHP extensions we need
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libpng-dev \
libjpeg-dev \
libpq-dev \
libldap2-dev \
libldb-dev \
libicu-dev \
libgmp-dev \
mysql-client \
libmagickwand-dev \
openssh-server vim curl wget tcptraceroute \
&& chmod 755 /bin/init_container.sh \
&& echo "root:Docker!" | chpasswd \
&& echo "cd /home" >> /etc/bash.bashrc \
&& ln -s /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/libldap.so \
&& ln -s /usr/lib/x86_64-linux-gnu/liblber.so /usr/lib/liblber.so \
&& ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h \
&& rm -rf /var/lib/apt/lists/* \
&& pecl install imagick-beta \
&& docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
&& docker-php-ext-configure mysqli --with-mysqli=mysqlnd \
&& docker-php-ext-install gd \
mysqli \
opcache \
pdo \
pdo_mysql \
pdo_pgsql \
pgsql \
ldap \
intl \
gmp \
zip \
bcmath \
mbstring \
pcntl \
xml \
xmlrpc \
&& docker-php-ext-enable imagick
###################
# Installing node #
###################
RUN apt-get update -yq && apt-get upgrade -yq && \
apt-get install -yq g++ libssl-dev apache2-utils curl git python make nano
# setting up npm for global installation without sudo
# http://stackoverflow.com/a/19379795/580268
RUN MODULES="local" && \
echo prefix = ~/$MODULES >> ~/.npmrc && \
echo "export PATH=\$HOME/$MODULES/bin:\$PATH" >> ~/.bashrc && \
. ~/.bashrc && \
mkdir ~/$MODULES && \
\
# install Node.js and npm
# https://gist.github.com/isaacs/579814#file-node-and-npm-in-30-seconds-sh
mkdir ~/node-latest-install && cd $_ && \
curl http://nodejs.org/dist/v8.11.3/node-v8.11.3.tar.gz | tar xz --strip-components=1 && \
./configure --prefix=~/$MODULES && \
make install && \
curl -L https://www.npmjs.org/install.sh | sh
# optional, check locations and packages are correct
# RUN which node; node -v; which npm; npm -v; \
# npm ls -g --depth=0
# Remove unnecessary packages
# RUN apt-get -yq purge g++ libssl-dev curl git python make nano
# RUN apt-get -yq autoremove
###################
RUN \
rm -f /var/log/apache2/* \
&& rmdir /var/lock/apache2 \
&& rmdir /var/run/apache2 \
&& rmdir /var/log/apache2 \
&& chmod 777 /var/log \
&& chmod 777 /var/run \
&& chmod 777 /var/lock \
&& chmod 777 /bin/init_container.sh \
&& cp /bin/apache2.conf /etc/apache2/apache2.conf \
&& rm -rf /var/www/html \
&& rm -rf /var/log/apache2 \
&& mkdir -p /home/LogFiles \
&& ln -s /home/LogFiles /var/log/apache2
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=60'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
RUN { \
echo 'error_log=/var/log/apache2/php-error.log'; \
echo 'display_errors=Off'; \
echo 'log_errors=On'; \
echo 'display_startup_errors=Off'; \
echo 'date.timezone=UTC'; \
} > /usr/local/etc/php/conf.d/php.ini
COPY sshd_config /etc/ssh/
EXPOSE 2222 8080
ENV APACHE_RUN_USER www-data
ENV PHP_VERSION 7.2.5
ENV PORT 8080
ENV WEBSITE_ROLE_INSTANCE_ID localRoleInstance
ENV WEBSITE_INSTANCE_ID localInstance
ENV PATH ${PATH}:/home/site/wwwroot
ENTRYPOINT ["/bin/init_container.sh"]
BUILD
FROM composer:latest as composer
FROM php:7.2.5-apache as apache
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN apt-get update && \
apt-get install git zip unzip -y
Edit 2:
It is important that if I remove the RUN npm... commands, then the whole build is a success and the result image contains the npm and I can use it (I've verified by using a container in interactive mode).
Edit 3:
Here's a lot lot simpler solution that can be tried out instantly:
FROM alpine as img1
RUN echo "$HOME" > $HOME/test.txt
FROM alpine as img2
RUN cat $HOME/test.txt
The result is: cat: can't open '/root/test.txt': No such file or directory
Two issues going on here. The "php:7.2.5-apache" image won't have /root/local/bin in the path, and you did not add it to the path during your build. The npm commands will work when you login interactively likely because of some changes to the shell login scripts that setup the environment. You'll need to run these environment setup scripts before running any npm commands, and that must be done within the same RUN command. To verify for yourself, you can check your .bashrc for variables or commands run to setup the npm environment. And you can verify the environment is different by comparing the PATH value with an env command in the interactive shell and in your build, you should see two different outputs if this is your issue. When I ran part of your run image, I saw the following in the .bashrc:
export PATH=$HOME/local/bin:$PATH
So you'll want to update the line in your Dockerfile for the run image:
ENV PATH /root/local/bin:${PATH}:/home/site/wwwroot
Per your edit 3, that's an entirely different issue. You created a file in one new image, and then went back to the base image where the file doesn't exist. If you wanted to see the file in a multi-stage build, then you either need to copy it between the stages, or use the previous image as your "from".
FROM alpine as img1
RUN echo "$HOME" > $HOME/test.txt
FROM alpine as img2
COPY --from=img1 /root/test.txt /root/test.txt
RUN cat $HOME/test.txt
or
FROM alpine as img1
RUN echo "$HOME" > $HOME/test.txt
FROM img1 as img2
RUN cat $HOME/test.txt

DockerFile SpringBoot App with Filebeat

I have a simple Spring Boot App that is dockerized, with this simple DockerFile
FROM openjdk
MAINTAINER matteoroxis
ADD target/example-service.jar example-service.jar
ENTRYPOINT ["java", "-jar", "/example-service.jar"]
EXPOSE 2222
I have necessity to use Filebeat to send log to a logstash environment; how can I launch Filebeat using my DockerFile?
FROM openjdk
MAINTAINER matteoroxis
ENV FILEBEAT_VERSION=1.2.3 \
FILEBEAT_SHA1=3fde7f5f5ea837140965a193bbb387c131c16d9c
COPY my-config/filebeat.yml /filebeat.yml
RUN set -x && \
apt-get update && \
apt-get install -y wget && \
wget https://download.elastic.co/beats/filebeat/filebeat-${FILEBEAT_VERSION}-x86_64.tar.gz -O /opt/filebeat.tar.gz && \
cd /opt && \
echo "${FILEBEAT_SHA1} filebeat.tar.gz" | sha1sum -c - && \
tar xzvf filebeat.tar.gz && \
cd filebeat-* && \
cp filebeat /bin && \
cd /opt && \
rm -rf filebeat* && \
apt-get purge -y wget && \
apt-get autoremove -y && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ADD target/example-service.jar example-service.jar
ENTRYPOINT ["java", "-jar", "/example-service.jar"]
CMD [ "filebeat", "-e" ]
EXPOSE 2222
Here is the filebeat dockerfile, for your reference

package.json file won't persist in docker container

I am trying to build a docker environment. I have made a Dockerfile which builds my image. Everything seems to work fine except for the issue that my package.json file won't persist inside the container. It seems as if it is getting removed somewhere. What I am doing wrong? Here is my Docker file content:
FROM ubuntu:14.04
RUN groupadd -r webuser && useradd -r -g webuser webuser && mkdir /home/webuser/ && chown webuser:webuser /home/webuser/
# install curl, apache, php
RUN sudo DEBIAN_FRONTEND=noninteractive \
apt-get -y update && \
apt-get -y install software-properties-common python-software-properties && \
add-apt-repository ppa:ondrej/php && \
apt-get -y update && \
apt-get install -y --force-yes \
curl \
git-core \
apache2 \
php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl \
php5.6-bz2 php5.6-zip && \
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');" && \
mv composer.phar /usr/local/bin/composer && \
chmod +x /usr/local/bin/composer
# install PHPUnit
RUN curl -L https://phar.phpunit.de/phpunit.phar -o phpunit.phar && \
chmod +x phpunit.phar && \
mv phpunit.phar /usr/local/bin/phpunit && \
chmod +x /usr/local/bin/phpunit
ADD package.json /var/www/html/package.json
WORKDIR /var/www/html
RUN chown -R webuser:webuser /var/www/html
USER webuser
# install node js 6
RUN NVM_DIR="/home/webuser/.nvm" && \
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash && \
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" && \
nvm install 6 && \
npm install -g webpack && \
npm install
RUN echo 'export NVM_DIR="/home/webuser/.nvm"\n\
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"'\
>> /home/webuser/.bashrc
COPY src /var/www/html/
USER root
EXPOSE 80
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
Try changing your ADD command to the following :
RUN mkdir -p /var/www/html
ADD package.json /var/www/html
Also make sure the package.json is present in the
FROM ubuntu:14.04
ADD package.json /var/www/html/package.json
RUN groupadd -r webuser && useradd -r -g webuser webuser && mkdir /home/webuser/ && chown webuser:webuser /home/webuser/
# install curl, apache, php
RUN sudo DEBIAN_FRONTEND=noninteractive \
apt-get -y update && \
apt-get -y install software-properties-common python-software-properties && \
add-apt-repository ppa:ondrej/php && \
apt-get -y update && \
apt-get install -y --force-yes \
curl \
git-core \
apache2 \
php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl \
php5.6-bz2 php5.6-zip && \
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');" && \
mv composer.phar /usr/local/bin/composer && \
chmod +x /usr/local/bin/composer
# install PHPUnit
RUN curl -L https://phar.phpunit.de/phpunit.phar -o phpunit.phar && \
chmod +x phpunit.phar && \
mv phpunit.phar /usr/local/bin/phpunit && \
chmod +x /usr/local/bin/phpunit
WORKDIR /var/www/html
RUN chown -R webuser:webuser /var/www/html
USER webuser
# install node js 6
RUN NVM_DIR="/home/webuser/.nvm" && \
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash && \
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" && \
nvm install 6 && \
npm install -g webpack && \
npm install
RUN echo 'export NVM_DIR="/home/webuser/.nvm"\n\
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"'\
>> /home/webuser/.bashrc
COPY src /var/www/html/
USER root
EXPOSE 80
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
i have executed your Dockerfile and had the same problem. It works if the ADD is at the beginning of the Dockerfile. But there are some other problems. The build process is stopping right after
chmod +x /usr/local/bin/composer
it wont install PHPUnit and nodeJS, set owner of the www directory and so on.
Maybe you should chain the whole RUN into one.
It seems like we need to have the package.json file within the source directory. Copying package.json separately and running the npm install pattern is used to make use of docker's caching system.

Resources