alpine linux do not execute compiled nodejs - docker

I'm trying to set up my docker file without success.
This is what i'm trying to do:
FROM alpine:3.5
ENV VERSION=4.8.1
RUN apk add --no-cache curl make gcc g++ python linux-headers binutils-gold gnupg libstdc++ tar xz && \
curl -sSL -o node.tar.xz https://nodejs.org/download/release/v${VERSION}/node-v${VERSION}-linux-x64.tar.xz && \
tar xJf node.tar.xz -C /usr/local --strip-components 1
CMD ["node", "--version"]
what I get as response is this:
Step 1 : FROM alpine:3.5
---> 4a415e366388
Step 2 : ENV VERSION 4.8.1
---> Using cache
---> 69c1a9ea15a9
Step 3 : RUN apk add --no-cache curl make gcc g++ python linux-headers binutils-gold gnupg libstdc++ tar xz && curl -sSL -o node.tar.xz https://nodejs.org/download/release/v${VERSION}/node-v${VERSION}-linux-x64.tar.xz && tar xJf node.tar.xz -C /usr/local --strip-components 1
---> Using cache
---> 7f508d49e0bc
Step 4 : CMD node --version
---> Running in 196a2ed982fd
---> c0e1fbc1fe23
Removing intermediate container 196a2ed982fd
Successfully built c0e1fbc1fe23
+ docker -H tcp://tjsu250n:2375 run --restart=always --name=barcode -d -p 9002:9001 tjdft_gesirh/barcode:194
c8483a53359d8a26b2f7e3e3bd01b3185a235f7722687f3aadf9c4ff6d4ac540
+ docker -H tcp://tjsu250n:2375 images -a
+ grep tjdft_gesirh/barcode
+ expr 194 - 1
+ awk {print $1}
+ grep 193
+ [ != ]
/tmp/hudson6046350871523920710.sh: 14: [: !=: unexpected operator
Finished: SUCCESS
But despite of that message, the command docker logs xpto returns:
standard_init_linux.go:175: exec user process caused "no such file or directory"
if I use RUN command to run this:
RUN ls -la /usr/local/bin/ && \
echo $PATH && \
npm --version
I get this as response:
Step 4 : RUN ls -la /usr/local/bin/ && echo $PATH && npm --version && ./usr/local/bin/node --version
---> Running in 1b6bd429d169
total 24244
drwxrwxr-x 2 500 500 27 Mar 21 19:14 .
drwxr-xr-x 6 root root 101 Mar 23 21:02 ..
-rwxrwxr-x 1 500 500 24825844 Mar 21 19:14 node
lrwxrwxrwx 1 500 500 38 Mar 21 19:14 npm -> ../lib/node_modules/npm/bin/npm-cli.js
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[91m/usr/local/bin/npm: exec: line 2: /usr/local/bin/node: not found
[0mtime="2017-03-23T18:12:59-03:00" level=info msg="The command '/bin/sh -c ls -la /usr/local/bin/ && \techo $PATH && \tnpm --version && \t./usr/local/bin/node --version' returned a non-zero code: 127"
Build step 'Execute shell' marked build as failure
Finished: FAILURE
I need some help.
## Edit ##
The error /usr/local/bin/node: not found occurred with oracle java too. Don't know why it is not executable from alpine.

I think you need to build node on alpine due to musl-libc.
See the official 7.7 alpine Dockerfile that does a build compared to the 7.7 Debian Dockerfile which uses the pre built package.
Alpine also do nodejs apk packages but they won't be as up to date as the release on nodejs.org.

It is possible to use apk to download nodejs. Package details can be found here
apk add nodejs
should install nodejs 6.10.1-r0.
Although building from source can be fun and challenging! Examples can be found here and here
Hope that helps!

Related

unable to run jmx file in docker

Connected server from windows machine using cygwin
Created one docker file in server
[root#serverhost uname]# touch Dockerfile
[root#serverhost uname]# vi Dockerfile
Dockerfile:
#1
FROM artifactory.xxx.net/java:8.212.0.1557388225_openjdk_74e62a71
#2
LABEL maintainer="xxx#domain.com"
# 3
ARG JMETER_VERSION="5.2"
# 4
ENV JMETER_HOME /opt/apache-jmeter-${JMETER_VERSION}
ENV JMETER_BIN ${JMETER_HOME}/bin
ENV MIRROR_HOST http://mirrors.ocf.berkeley.edu/apache/jmeter
ENV JMETER_DOWNLOAD_URL ${MIRROR_HOST}/binaries/apache-jmeter-${JMETER_VERSION}.tgz
ENV JMETER_PLUGINS_DOWNLOAD_URL http://repo1.maven.org/maven2/kg/apc
ENV JMETER_PLUGINS_FOLDER ${JMETER_HOME}/lib/ext/
# 5
RUN apk update \
&& apk upgrade \
&& apk add ca-certificates \
&& update-ca-certificates \
&& apk add --update openjdk8-jre tzdata curl unzip bash \
&& cp /usr/share/zoneinfo/Europe/Rome /etc/localtime \
&& echo "Europe/Rome" > /etc/timezone \
&& rm -rf /var/cache/apk/* \
&& mkdir -p /tmp/dependencies \
&& curl -L --silent ${JMETER_DOWNLOAD_URL} > /tmp/dependencies/apache-jmeter-${JMETER_VERSION}.tgz \
&& mkdir -p /opt \
&& tar -xzf /tmp/dependencies/apache-jmeter-${JMETER_VERSION}.tgz -C /opt \
&& rm -rf /tmp/dependencies
# 6
RUN curl -L --silent ${JMETER_PLUGINS_DOWNLOAD_URL}/jmeter-plugins-dummy/0.2/jmeter-plugins-dummy-0.2.jar -o ${JMETER_PLUGINS_FOLDER}/jmeter-plugins-dummy-0.2.jar
RUN curl -L --silent ${JMETER_PLUGINS_DOWNLOAD_URL}/jmeter-plugins-cmn-jmeter/0.5/jmeter-plugins-cmn-jmeter-0.5.jar -o ${JMETER_PLUGINS_FOLDER}/jmeter-plugins-cmn-jmeter-0.5.jar
# 7
ENV PATH $PATH:$JMETER_BIN
# 8
COPY launch.sh /
#9
WORKDIR ${JMETER_HOME}
#10
ENTRYPOINT ["/launch.sh"]
Created launch.sh file in same folder where docker is created
[root#serverhost uname]# touch launch.sh
[root#serverhost uname]# vi launch.sh
launch.sh file
#!/bin/bash
set -e
freeMem=`awk '/MemFree/ { print int($2/1024) }' /proc/meminfo`
s=$(($freeMem/10*8))
x=$(($freeMem/10*8))
n=$(($freeMem/10*2))
export JVM_ARGS="-Xmn${n}m -Xms${s}m -Xmx${x}m"
echo "START Running Jmeter on `date`"
echo "JVM_ARGS=${JVM_ARGS}"
echo "jmeter args=$#"
# Keep entrypoint simple: we must pass the standard JMeter arguments
jmeter $#
echo "END Running Jmeter on `date`"
Built the docker and tagged it
[root#serverhost uname]# docker build .
[root#serverhost uname]# docker tag 090847728937 jmautomation:1.0
exit from server and copied my local jmx file folder to server
uname#QINDW191 /cygdrive/c/jmeter/$ scp -r jmeterscript uname#serverhost:~/
[uname#serverhost~]$ ls -lrt
total 12
-rw-r--r--. 1 root root 1678 Nov 26 10:29 Dockerfile
-rw-r--r--. 1 root root 331 Nov 26 11:00 launch.sh
drwxrwx---. 2 uname uname 4096 Nov 28 09:17 jmeterscript
Running jmx file in docker by copying folder to docker mnt/jmeter folder and running jmx file from there:
[root#serverhost uname]# docker run -v /home/uname/jmeterscript:/mnt/jmeter jmautomation:1.0 -n -Jenv=devint -t /mnt/jmeter/api_regression.jmx -l /mnt/jmeter/result.xml
[root#serverhost uname]# docker run --volume "/home/uname/jmeterscript":/mnt/jmeter jmautomation:1.0 -n -Jenv=devint -t /mnt/jmeter/api_regression.jmx -l /mnt/jmeter/result.xml
[root#serverhost uname]# docker run --volume "/home/uname/jmeterscript":/mnt/jmeter jmautomation:1.0 -n -Jenv="devint" -t /mnt/jmeter/api_regression.jmx -l /mnt/jmeter/result.xml
[root#serverhost uname]# docker run --volume "/home/uname/jmeterscript":/mnt jmautomation:1.0 -n -Jenv=devint -t /mnt/api_regression.jmx -l /mnt/result.xml
Tried to run with all above commands every time I am facing below error
docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"-n\": executable file not found in $PATH": unknown.
ERRO[0001] error waiting for container: context canceled
Can anyone please help me what I am missing?

Docker compose throws - adduser: group 'www-data' in use

I have a docker-composer.yml file which used to work just fine a couple of months ago, but now when I run it throws an error.
First, this is my file structure.
.data/db
logs
mariadb
nginx
php7-fpm
src/public
.env
.gitignore
README
docker-compose.yml
The only mention of the error i.e www-data is in two of the files. php7-fpm/Dockerfile and nginx/Dockerfile
Here is the content of these files:
php-fpm/Dockerfile
....
RUN apt-get update && apt-get install -y procps
RUN usermod -u 1000 www-data
USER www-data
WORKDIR /var/www
nginx/Dockerfile
FROM nginx:alpine
COPY ./config/nginx.conf /etc/nginx/
COPY ./sites /etc/nginx/sites-available
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
&& adduser -D -H -u 1000 -s /bin/bash www-data
ARG PHP_UPSTREAM_CONTAINER=php-fpm
ARG PHP_UPSTREAM_PORT=9000
# Set upstream conf and remove the default conf
RUN echo "upstream php-upstream { server ${PHP_UPSTREAM_CONTAINER}:${PHP_UPSTREAM_PORT}; }" > /etc/nginx/conf.d/upstream.conf \
&& rm /etc/nginx/conf.d/default.conf
CMD ["nginx"]
The docker-compose.yml file is a generic one, there is no tampering with user groups, but here is a pastebin for anyone who wants to take a look.
https://pastebin.com/ivRfPvZz
This is the partial output from the docker-compose up -d command.
Image for service php-fpm was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Building nginx
Step 1/8 : FROM nginx:alpine
alpine: Pulling from library/nginx
Digest: sha256:17bd1698318e9c0f9ba2c5ed49f53d690684dab7fe3e8019b855c352528d57be
Status: Downloaded newer image for nginx:alpine
---> ea1193fd3dde
Step 2/8 : COPY ./config/nginx.conf /etc/nginx/
---> 65c115482d37
Step 3/8 : COPY ./sites /etc/nginx/sites-available
---> 1fbe81620355
Step 4/8 : RUN apk update && apk upgrade && apk add --no-cache bash && adduser -D -H -u 1000 -s /bin/bash www-data
---> Running in c631ccdf63f2
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
v3.9.4-61-g22a1991b6a [http://dl-cdn.alpinelinux.org/alpine/v3.9/main]
v3.9.4-57-gb40ea6190b [http://dl-cdn.alpinelinux.org/alpine/v3.9/community]
OK: 9776 distinct packages available
(1/1) Upgrading libbz2 (1.0.6-r6 -> 1.0.6-r7)
OK: 27 MiB in 37 packages
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/2) Installing readline (7.0.003-r1)
(2/2) Installing bash (4.4.19-r1)
Executing bash-4.4.19-r1.post-install
Executing busybox-1.29.3-r10.trigger
OK: 29 MiB in 39 packages
adduser: group 'www-data' in use
Service 'nginx' failed to build: The command '/bin/sh -c apk update && apk upgrade && apk add --no-cache bash && adduser -D -H -u 1000 -s /bin/bash www-data' returned a non-zero code: 1
You can see the error is:
adduser: group 'www-data' in use
Service 'nginx' failed to build: The command '/bin/sh -c apk update && apk upgrade && apk add --no-cache bash && adduser -D -H -u 1000 -s /bin/bash www-data' returned a non-zero code: 1
but I don't know how to fix this.
See this, when you use FROM nginx:alpine, in fact it sames with using nginx:1.17.1-alpine because they are just different tags for same image id.
But several month ago, when you use nginx:alpine, latest maybe others, E.g. nginx:1.14.2-alpine, so when rebuild using the same dockerfile, the base image indeed changed. I strongly suggest you use an explicit tag not latest as base image to assure definiteness.
Finally, what happened for several month ago?
Use nginx:1.14.2-alpine, maybe not this version, just an example:
$ docker run --rm -it nginx:1.14.2-alpine cat /etc/group | grep www-data
You can see there is no www-data group in the image, so you can use next to add a new user also a new group with the name www-data:
adduser -D -H -u 1000 -s /bin/bash www-data
Use nginx:1.17.1-alpine, which currently same as nginx:alpine:
$ docker run --rm -it nginx:1.17.1-alpine cat /etc/group | grep www-data
www-data:x:82:
You can see there is a default www-data group in this image, don't know how it generates, in a word, the image update bring something difference.
So, as already a www-data group there, what you have to do is change your command to next to join a existed group:
adduser -D -H -u 1000 -s /bin/bash www-data -G www-data
You can find the DockerFile inside laradock/nginx folder. Just change the line
&& adduser -D -H -u 1000 -s /bin/bash www-data
to
&& adduser -D -H -u 1000 -s /bin/bash www-data -G www-data
This specifies the group that the user is a member of. Once done, build and bring your containers up with
docker-compose build --no-cache nginx
docker-compose up -d
I'm having this issue with Alpine 3.14, where the www-data group already exists in the image.
Adding (delgroup www-data || true) before the line with adduser in it will fix the problem.
&& apk upgrade \
&& apk add --no-cache bash \
&& (delgroup www-data || true) \
&& adduser -D -H -u 1000 -s /bin/bash www-data
The parentheses with the || true will ensure that the command won't fail if the group does not exist, so it is backward compatible.

Build Docker Container

In the context of a project, I have to run an sbt application in a Docker container.
That's why I created a Dockerfile, but when I try to build the container, I got an error but I don't understand why.
My code looks like this:
FROM centos:latest
RUN curl -LO "https://nodejs.org/dist/latest/node-v10.7.0-linux-x64.tar.gz" && tar -xzf node-v10.7.0-linux-x64.tar.gz -C /usr/local --strip-components=1 && rm node-v0.12.5-linux-x64.tar.gz
ADD app/abc/
WORKDIR /app
RUN npm install
RUN npm run build
CMD sbt plt/run
EXPOSE 9001
And that's the error:
Sending build context to Docker daemon 745.3MB
Step 1/8 : FROM centos:latest
---> 49f7960eb7e4
Step 2/8 : RUN curl -LO "https://nodejs.org/dist/latest/node-v10.7.0-linux-x64.tar.gz" && tar -xzf node-v10.7.0-linux-x64.tar.gz -C /usr/local --strip-components=1 && rm node-v0.12.5-linux-x64.tar.gz -o StrictHostKeyChecking=no
---> Running in d863c7cb398e
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0curl: (6) Could not resolve host: nodejs.org; Unknown error
The command '/bin/sh -c curl -LO "https://nodejs.org/dist/latest/node-v10.7.0-linux-x64.tar.gz" && tar -xzf node-v10.7.0-linux-x64.tar.gz -C /usr/local --strip-components=1 && rm node-v0.12.5-linux-x64.tar.gz -o StrictHostKeyChecking=no' returned a non-zero code: 6
Did someone know what's the issue ?
Thanks a lot.
F.M
The message returned a non-zero code means the command failed.
If you read the previous line, curl returned the following error: Could not resolve host: nodejs.org; Unknown error.
It means that during the build, you couldn't access to th "nodejs.org" hostname.
I also can't use your command line (I have the same error). You should follow their documentation for installing Node.js for CentOS:
RUN curl --silent --location https://rpm.nodesource.com/setup_10.x | bash - && yum -y install nodejs
If you can use another system than CentOS, you could use a Node.JS base image from hub.docker.com.
In your Dockerfile:
FROM node:8 (or another version)

Docker build Gentoo operation not permitted

I have a docker-compose with this container to build Gentoo
default:
build: docker/gentoo
hostname: default.jpo.net
My Dockerfile to setup Gentoo in multi-stage build is
FROM gentoo/portage as portage
FROM gentoo/stage3-amd64
COPY --from=portage /usr/portage /usr/portage
RUN emerge --jobs $(nproc) -qv www-servers/apache net-misc/curl net-misc/openssh
RUN /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
RUN /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
RUN sed -i 's/#PubkeyAuthentication/PubkeyAuthentication/' /etc/ssh/sshd_config
RUN mkdir -p /root/.ssh && chmod 700 /root/.ssh && touch /root/.ssh/authorized_keys
RUN wget -O telegraf.tar.gz http://get.influxdb.org/telegraf/telegraf-0.11.1-1_linux_amd64.tar.gz \
&& tar xvfz telegraf.tar.gz \
&& rm telegraf.tar.gz \
&& mv /usr/lib/telegraf /usr/lib64/telegraf \
&& rm -rf /usr/lib && ln -s /usr/lib64 /usr/lib
ADD telegraf.conf /etc/telegraf/telegraf.conf
COPY entrypoint.sh /
COPY infinite_curl.sh /
RUN chmod u+x /entrypoint.sh /infinite_curl.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["telegraf", "-config", "/etc/telegraf/telegraf.conf"]
The problem is the build fail during the emerge command when it setup packages.
Then I get this error
PermissionError: [Errno 1] Operation not permitted
* ERROR: dev-libs/apr-1.5.2::gentoo failed (install phase):
* dodoc failed
I tried adding privileged=true in my docker-compose file and with adding USER root inside my Dockerfile without success.
I also tried to use the last version of openssh without success too.
I searched the Internet but I haven't found anything successfull.
Docker version
Docker version 17.12.0-ce, build c97c6d6
Docker-compose version
docker-compose version 1.18.0, build 8dd22a9
I'm on Ubuntu 16.04 and this build work well on Ubuntu 17.10 with same docker/docker-compose versions
Do you have some clues ?
Looking at in src-install() for that ebuild, this appears to be a bug upstream.
# Prallel install breaks since apr-1.5.1
#make -j1 DESTDIR="${D}" install || die
There are several two bugs related to building apr in parallel.

Building a Docker Image with rstan on rocker/verse

I am planning to run a customized Rstudio with both tidyverse, rmarkdown and rstan pre-installed on Digital Ocean's Docker 17.03.0-ce on 16.04.
On Docker Hub, there is already a pre-built image: Rocker/verse that has tidyverse and rmarkdown functionality. So my plan was to simply get the latest version of Rocker/verse and add a new layer of rstan. I use the dockerfile of jonzelner/rstan and jrnold/rstan and update them as below:
FROM rocker/verse:latest
# Install essentials
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
clang-3.6
# Global site-wide config
RUN mkdir -p $HOME/.R/ \
&& echo "\nCXX=clang++ -ftemplate-depth-256\n" >> $HOME/.R/Makevars \
&& echo "CC=clang\n" >> $HOME/.R/Makevars
# Install rstan
RUN install2.r --error \
inline \
RcppEigen \
StanHeaders \
rstan \
KernSmooth
# Config for rstudio user
RUN mkdir -p /home/rstudio/.R/ \
&& echo "\nCXX=clang++ -ftemplate-depth-256\n" >> /home/rstudio/.R/Makevars \
&& echo "CC=clang\n" >> /home/rstudio/.R/Makevars \
&& echo "CXXFLAGS=-O3\n" >> /home/rstudio/.R/Makevars \
&& echo "\nrstan::rstan_options(auto_write = TRUE)" >> /home/rstudio/.Rprofile \
&& echo "options(mc.cores = parallel::detectCores())" >> /home/rstudio/.Rprofile
# Install loo
RUN install2.r --error \
matrixStats \
loo
However, my attempt to build this image (docker build -t image_name .) ended in error. The results are provided below:
Sending build context to Docker daemon 2.56 kB
Step 1/6 : FROM rocker/verse:latest
---> 7ad7d994bffd
Step 2/6 : RUN apt-get update && apt-get install -y --no-install-recommends clang-3.6
---> Using cache
---> 77473c759438
Step 3/6 : RUN mkdir -p $HOME/.R/ && echo "\nCXX=clang++ -ftemplate-depth-256\n" >> $HOME/.R/Makevars && echo "CC=clang\n" >> $HOME/.R/Makevars
---> Using cache
---> a5b06d28b9fe
Step 4/6 : RUN install2.r --error inline RcppEigen StanHeaders rstan KernSmooth
---> Running in 86b52d5a76f3
trying URL 'https://cran.rstudio.com/src/contrib/inline_0.3.14.tar.gz'
Content type 'unknown' length 18002 bytes (17 KB)
==================================================
downloaded 17 KB
* installing *source* package ‘inline’ ...
** package ‘inline’ successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (inline)
The downloaded source packages are in
‘/tmp/downloaded_packages’
trying URL 'https://cran.rstudio.com/src/contrib/RcppEigen_0.3.2.9.0.tar.gz'
Content type 'unknown' length 1209128 bytes (1.2 MB)
==================================================
downloaded 1.2 MB
* installing *source* package ‘RcppEigen’ ...
** package ‘RcppEigen’ successfully unpacked and MD5 sums checked
** libs
clang++ -ftemplate-depth-256 -I/usr/local/lib/R/include -DNDEBUG -I/usr/local/include -I"/usr/local/lib/R/site-library/Rcpp/include" -I../inst/include -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c RcppEigen.cpp -o RcppEigen.o
/bin/bash: clang++: command not found
/usr/local/lib/R/etc/Makeconf:141: recipe for target 'RcppEigen.o' failed
make: *** [RcppEigen.o] Error 127
ERROR: compilation failed for package ‘RcppEigen’
* removing ‘/usr/local/lib/R/site-library/RcppEigen’
Error in install.packages(pkgs = f, lib = lib, repos = if (isMatchingFile(f)) NULL else rep, :
installation of package ‘RcppEigen’ had non-zero exit status
The command '/bin/sh -c install2.r --error inline RcppEigen StanHeaders rstan KernSmooth' returned a non-zero code: 1
Some similar questions about a package having non-zero exit status have to do with memory, so I tried to increase the Docker memory on my local machine, but still no luck. Is there any thing I can do to successfully build this image?
As you see in the error output, the installation process cannot find the compiler:
/bin/bash: clang++: command not found
Be aware that this is the output from trying to install clang-3.6 in a rocker/verse container:
root#8ea0d98e67c3:/# apt-get install -y --no-install-recommends clang-3.6
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'python-clang-3.6' for regex 'clang-3.6'
0 upgraded, 0 newly installed, 0 to remove and 15 not upgraded.
It appears that this image doesn't come with Clang 3.6 in its repositories. And this name instead points to python-clang-3.6; Clang bindings for the Python programming language.
Unless you absolutely want 3.6, I would install the plain clang package that points to 3.5, and then re-run the Docker build process.
apt-get install clang

Resources