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)
Related
I just make multarch images by using buildx
When running docker buildx build --platform linux/amd64,linux/arm64 -t maskertim/zookeeper-demo .
Error Message
The Error as following:
------
> [linux/arm64 3/5] RUN curl "https://archive.apache.org/dist/kafka/2.8.0/kafka_2.13-2.8.0.tgz" -o /tmp/kafka/kafka.tgz && mkdir /kafka && cd /kafka && tar -xzvf /tmp/kafka/kafka.tgz --strip 1:
#8 0.915 % Total % Received % Xferd Average Speed Time Time Time Current
#8 0.916 Dload Upload Total Spent Left Speed
100 68.0M 100 68.0M 0 0 936k 0 0:01:14 0:01:14 --:--:-- 3475k
#8 75.45 tar: Child returned status 1
#8 75.45 tar: Error is not recoverable: exiting now
------
dockerfile:9
--------------------
8 |
9 | >>> RUN curl "https://archive.apache.org/dist/kafka/${KAFKA_VERSION}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz" \
10 | >>> -o /tmp/kafka/kafka.tgz && \
11 | >>> mkdir /kafka && cd /kafka && \
12 | >>> tar -xzvf /tmp/kafka/kafka.tgz --strip 1
13 |
--------------------
error: failed to solve: process "/dev/.buildkit_qemu_emulator /bin/sh -c curl \"https://archive.apache.org/dist/kafka/${KAFKA_VERSION}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz\" \t-o /tmp/kafka/kafka.tgz && \tmkdir /kafka && cd /kafka && \ttar -xzvf /tmp/kafka/kafka.tgz --strip 1" did not complete successfully: exit code: 2
Dockerfile
And this is my dockerfile:
FROM openjdk:11.0.12-jre-buster
ENV KAFKA_VERSION 2.8.0
ENV SCALA_VERSION 2.13
RUN mkdir /tmp/kafka && \
apt-get update && \
apt-get install -y curl
RUN curl "https://archive.apache.org/dist/kafka/${KAFKA_VERSION}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz" \
-o /tmp/kafka/kafka.tgz && \
mkdir /kafka && cd /kafka && \
tar -xzvf /tmp/kafka/kafka.tgz --strip 1
COPY start-zookeeper.sh /usr/bin
RUN chmod +x /usr/bin/start-zookeeper.sh
CMD ["start-zookeeper.sh"]
What happens? I have no idea why to occur this error and no way to solve it.
Unzip it first:
gzip -d /tmp/kafka/kafka.tgz
And after that untar it with:
tar xpf /tmp/kafka/kafka.tar
I had the same problem and discovered https://stackoverflow.com/a/71143883
Running
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
allowed me to keep the decompression step in the tar command
I think the problem is related to tar or more specific one of its child processes is failing to untar or unzip because of a missing dependency, which seems not to be present in the qemu_emulator that buildx uses.
I ended up using the ADD command in the dockerfile instead of RUN tar, which has that functionality built in.
Found a strange issue today, COPY fails when i try to copy unzipped files after docker unzip instruction. Locally this works fine, however it fails in gitlab pipeline.
Dockerfile
FROM caapim/gateway:10.0.00
ARG API_NAME=gateway
USER root
# Install awscli
RUN yum -y update && \
yum clean all && \
yum -y install awscli
# Install newrelic
RUN mkdir -p /opt/newrelic/extensions && \
curl -O https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip && \
unzip newrelic-java.zip
#Copy newrelic specific files in /opt/newrleic/newrelic.jar
RUN ls newrelic/
#COPY ./newrelic/newrelic.jar /opt/newrelic/newrelic.jar
ADD ./newrelic/newrelic.jar /opt/newrelic/newrelic.jar
Gitlab pipeline logs
Step 6/18 : RUN mkdir -p /opt/newrelic/extensions && curl -O https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip && unzip newrelic-java.zip
---> Running in 9d1d1671cb48
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 17.8M 100 17.8M 0 0 40.1M 0 --:--:-- --:--:-- --:--:-- 40.2M
Archive: newrelic-java.zip
creating: newrelic/
inflating: newrelic/LICENSE
inflating: newrelic/THIRD_PARTY_NOTICES.md
inflating: newrelic/newrelic.jar
inflating: newrelic/extension.xsd
inflating: newrelic/newrelic.yml
inflating: newrelic/extension-example.xml
inflating: newrelic/newrelic-api.jar
inflating: newrelic/newrelic-api-sources.jar
inflating: newrelic/newrelic-api-javadoc.jar
Removing intermediate container 9d1d1671cb48
---> 4d7c05a4e42f
Step 7/18 : RUN ls newrelic/
---> Running in 2c01dd0f64c7
extension-example.xml
extension.xsd
LICENSE
newrelic-api.jar
newrelic-api-javadoc.jar
newrelic-api-sources.jar
newrelic.jar
newrelic.yml
THIRD_PARTY_NOTICES.md
Removing intermediate container 2c01dd0f64c7
---> a46648ac1aa9
Step 8/18 : ADD ./newrelic/newrelic.jar /opt/newrelic/newrelic.jar
Service 'gateway' failed to build : ADD failed: stat /var/lib/docker/tmp/docker-builder027083691/newrelic/newrelic.jar: no such file or directory
Removing network build_default
Network build_default not found.
Note: I have removed few instruction and add some for RCA.
FROM caapim/gateway:10.0.00
ARG API_NAME=gateway
USER root
# Install awscli
RUN yum -y update && \
yum clean all && \
yum -y install awscli
# Install newrelic
RUN mkdir -p /opt/newrelic/extensions && \
cd /opt/ \
curl -O https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip && \
unzip newrelic-java.zip
RUN cp /newrelic/newrelic.jar /opt/newrelic/newrelic.jar
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.
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!
In Jenkins I installed Docker build step plugin.
In Jenkins, created job and in it, executed docker command selected build image. The image is created using the Dockerfile.The Dockerfile is :
FROM ubuntu:latest
#OS Update
RUN apt-get update
RUN apt-get -y install git git-core unzip python-pip make wget build-essential python-dev libpcre3 libpcre3-dev libssl-dev vim nano net-tools iputils-ping supervisor curl supervisor
WORKDIR /home/wipro
#Mongo Setup
RUN curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-3.0.2.tgz && tar -xzvf mongodb-linux-x86_64-3.0.2.tgz && cd mongodb-linux-x86_64-3.0.2/bin && cp * /usr/bin/
#RUN mongod --dbpath /home/azureuser/CI_service/data/ --logpath /home/azureuser/CI_service/log.txt --logappend --noprealloc --smallfiles --port 27017 --fork
#Node Setup
#RUN curl -O https://nodejs.org/dist/v0.12.7/node-v0.12.7.tar.gz && tar -xzvf node-v0.12.7.tar.gz && cd node-v0.12.7
#RUN cd /opt/node-v0.12.7 && ./configure && make && make install
#RUN cp /usr/local/bin/node /usr/bin/ && cp /usr/local/bin/npm /usr/bin/
RUN wget https://nodejs.org/dist/v0.12.7/node-v0.12.7-linux-x64.tar.gz
RUN cd /usr/local && sudo tar --strip-components 1 -xzf /home/wipro/node-v0.12.7-linux-x64.tar.gz
RUN npm install forever -g
#CI SERVICE
ADD prod /home//
ADD servicestart.sh /home/
RUN chmod +x /home/servicestart.sh
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["sh", "/home/servicestart.sh"]
EXPOSE 80
EXPOSE 27017
Then I tried to create the container and container is created.
When I tried to start the container, the container is not running.
When I checked with command:
docker ps -a
, it shows status as created only.
Its not in running or Exited state.
The output of docker ps -a is:
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ac762c4dc84 d85c2d90be53 "sh /home/servi" 15 hours ago Created hungry_liskov
7d8864940515 d85c2d90be53 "sh /home/servi" 16 hours ago Created ciservice
How to start the container using jenkins?
It depends on your container main command (ENTRPOINT + CMD)
A created state (for non data-volume container) means the main command failed to execute.
Try a docker logs <container_id> to see if there is any error message recorded.
CMD ["sh", "/home/servicestart.sh"] should be:
CMD ["/home/servicestart.sh"]
(The default ENTRYPOINT for Ubuntu should be ["sh", "-c"], so no need to repeat an "sh")