Running concatenated commands fails - docker

While trying to build the following Dockerfile
FROM ruby:2.7.1-alpine3.12
RUN apk update && \
apk --no-cache add git
# Install Syslog
RUN wget -O /usr/remote_syslog_linux_i386.tar.gz https://github.com/papertrail/remote_syslog2/releases/download/v0.20/remote_syslog_linux_i386.tar.gz && \
tar xzf /usr/remote_syslog_linux_i386.tar.gz -C /usr
I get the following error
However, the following Dockerfile
FROM ruby:2.7.1-alpine3.12
RUN apk update && \
apk --no-cache add git
# Install Syslog
RUN wget -O /usr/remote_syslog_linux_i386.tar.gz https://github.com/papertrail/remote_syslog2/releases/download/v0.20/remote_syslog_linux_i386.tar.gz
RUN tar xzf /usr/remote_syslog_linux_i386.tar.gz -C /usr
doesn't run into any error.
What am I missing?

Related

docker suddenly stopped working, executor failed running [/bin/sh -c echo

Hello this is my docker file:
FROM golang:alpine3.15 as builder
RUN apk add ca-certificates git make gcc musl-dev libc6-compat curl chromium bash curl
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/v3.12/main" >> /etc/apk/repositories \
&& apk upgrade -U -a \
&& apk add \
libstdc++ \
chromium \
harfbuzz \
nss \
freetype \
ttf-freefont \
font-noto-emoji \
wqy-zenhei
RUN mkdir /build
ADD go.* /build/
WORKDIR /build
RUN go mod download -x
ADD main.go /build/
RUN CGO_ENABLED=0 GOOS=linux go build -a -o /api
FROM alpine:3.15
COPY --from=builder /api .
EXPOSE 8080
ENTRYPOINT [ "/api" ]
STOPSIGNAL SIGKILL
I have been using same image on save ubuntu version, since past 4 months. But now when I run docker-compose up --build I always get this error:
failed to solve: executor failed running [/bin/sh -c echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories && echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && echo "http://dl-cdn.alpinelinux.org/alpine/v3.12/main" >> /etc/apk/repositories && apk upgrade -U -a && apk add libstdc++ chromium harfbuzz nss freetype ttf-freefont font-noto-emoji wqy-zenhei]: exit code: 1
What could be the issue? Thanks
Found these errors too:
#0 3.144 ERROR: ca-certificates-bundle-20220614-r2: trying to overwrite etc/ssl1.1/cert.pem owned by libcrypto1.1-1.1.1q-r0.
#0 3.144 ERROR: ca-certificates-bundle-20220614-r2: trying to overwrite etc/ssl1.1/certs owned by libcrypto1.1-1.1.1q-r0.

Unable to Copy s3 files inside Docker container

Am new to docker and aws. I am trying to create a Jmeter Image and pass on the JMX script during runtime. For that, i thought copying files from S3 inside a container will be a best fit. So initially i tried to copy the files from s3 to my local host using the below command
aws s3 cp s3://bucketname/sample.jmx .
I was able to download the file successfully into my local system.
After then i have created a docker images with latest AWS CLI installed and tried the same, the message shows "download: s3://bucketname/sample.jmx to current folder " but am not able to see the file.
But on the other hand, i was able to copy the file from docker to S3 using the command
aws s3 cp /tmp/sample.jmx s3://bucketname/
Further details :
Image on - alpine:3.12.4
Credentials - Passed inline with the docker run command like below
docker run -it --rm -e AWS_DEFAULT_REGION='us-east-2' -e AWS_ACCESS_KEY_ID='aaaaaa' -e AWS_SECRET_ACCESS_KEY='dsfssdfds' dockerimage aws s3 cp s3://bucketname/sample.jmx /tmp
Complete Docker file :
FROM alpine:3.12.4
ARG JMETER_VERSION="5.3"
ENV JMETER_HOME /opt/apache-jmeter-${JMETER_VERSION}
ENV JMETER_BIN ${JMETER_HOME}/bin
ENV JMETER_DOWNLOAD_URL https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-${JMETER_VERSION}.tgz
# Install extra packages
# Set TimeZone, See: https://github.com/gliderlabs/docker-alpine/issues/136#issuecomment-612751142
ARG TZ="Europe/Amsterdam"
ENV TZ ${TZ}
RUN apk update \
&& apk upgrade \
&& apk add ca-certificates \
&& update-ca-certificates \
&& apk add --update openjdk8-jre tzdata curl unzip bash \
&& apk add --no-cache nss \
&& 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
# TODO: plugins (later)
# && unzip -oq "/tmp/dependencies/JMeterPlugins-*.zip" -d $JMETER_HOME
# Set global PATH such that "jmeter" command is found
ENV PATH $PATH:$JMETER_BIN
RUN apk update && \
apk add --no-cache python3 py3-pip\
&& pip3 install --upgrade pip
RUN pip3 --no-cache-dir install --upgrade awscli
ENV PATH $PATH:/usr/bin/aws
CMD ["/bin/bash"]
I would really need some help here.

Problems installing csvtk with Docker using debian:stretch-slim

I am a newbie to Docker and I am trying to install csvtk via Docker using debian:stretch-slim.
This below is my Dockerfile
FROM debian:stretch-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
jq \
perl \
python3 \
wget \
&& rm -rf /var/lib/apt/lists/*
RUN wget -qO- https://github.com/shenwei356/csvtk/releases/download/v0.23.0/csvtk_linux_amd64.tar.gz | tar -xz \
&& cp csvtk /usr/local/bin/
It fails at the csvtk step with the below error message:
Step 3/3 : RUN wget -qO- https://github.com/shenwei356/csvtk/releases/download/v0.23.0/csvtk_linux_amd64.tar.gz | tar -xz && cp csvtk /usr/local/bin/
---> Running in 0f3a0e75a5de
gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
The command '/bin/sh -c wget -qO- https://github.com/shenwei356/csvtk/releases/download/v0.23.0/csvtk_linux_amd64.tar.gz | tar -xz && cp csvtk /usr/local/bin/' returned a non-zero code: 2
I would appreciate any help/suggestions.
Thanks in advance.
wget was exiting with error code meaning 5 SSL verification failed on wget. From this answer, you just needed to install ca-certificates before wget.
This Dockerfile should build successfully:
FROM debian:stretch-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
jq \
perl \
python3 \
wget \
# added this package to help with ssl certs in Docker
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
RUN wget -qO- https://github.com/shenwei356/csvtk/releases/download/v0.23.0/csvtk_linux_amd64.tar.gz | tar -xz \
&& cp csvtk /usr/local/bin/
As a general tip when debugging issues like these, it's likely easiest to remove the offending RUN line from your Dockerfile and then try building and running the container in a shell and manually executing the commands you want. Like this:
docker build -t test:v1 .
docker run --rm -it test:v1 /bin/bash
# run commands manually and check the full error output
While combining different RUN instructions with && is best practice to reduce the number of image layers, it's difficult to debug when building.

How to decrease the size of docker image with gRPC in golang supported?

I have some server and clients who are communicating using gRPC/golang. Now I want to containerize my application but the size of the docker image containing goland execution and grpc support is larger(more than 1GB). I would like to decrease the size of the docker image.
The required golang version is 1.9 and higher. Here is the Dockerfile script is given. If there is other way please suggest it.
FROM golang:1.11
RUN apt-get update && \
apt-get -y install git unzip build-essential autoconf libtool
RUN git clone https://github.com/google/protobuf.git && \
cd protobuf && \
./autogen.sh && \
./configure && \
make && \
make install && \
ldconfig && \
make clean && \
cd .. && \
rm -r protobuf
RUN go get google.golang.org/grpc
RUN go get github.com/golang/protobuf/protoc-gen-go
RUN ls -la
WORKDIR /helloworld
COPY . /helloworld
RUN protoc -I helloworld/ helloworld/helloworld.proto --go_out=plugins=grpc:helloworld
CMD ["go", "run", "helloworld/greeter_server/main.go"]
try to make a multistage docker image like this
# Compile stage
FROM golang:1.11 as build-env
RUN apt-get update && \
apt-get -y install git unzip build-essential autoconf libtool
RUN git clone https://github.com/google/protobuf.git && \
cd protobuf && \
./autogen.sh && \
./configure && \
make && \
make install && \
ldconfig && \
make clean && \
cd .. && \
rm -r protobuf
RUN go get google.golang.org/grpc
RUN go get github.com/golang/protobuf/protoc-gen-go
RUN ls -la
WORKDIR /helloworld
COPY . /helloworld
RUN protoc -I helloworld/ helloworld/helloworld.proto --go_out=plugins=grpc:helloworld
RUN go build -o server helloworld/greeter_server/main.go
# Making image
FROM alpine:3.8 AS host
RUN apk add --no-cache \
ca-certificates
COPY --from=build-env /helloworld/server /
# copy any other files you need
WORKDIR /
EXPOSE 8000
CMD ["server"]
You can try to use distroless base images and multi-stage builds. That might help you.

Dockerfile issues

Hi I got a project with a dockerfile, and I am trying to build the dockerfile to run the project in the environment it was created but I seem to get an error at step 5 of the build and when I look at the dockerfile I find the code a bit strange/I dont understand it at that point.
This is the dockerfile:
FROM node:8.10-alpine
ENV NODE_ENV development
# Create app directory
WORKDIR /var/app
# Install Node packages
COPY package.json package.json
RUN apk install git \
&& npm i \
&& apk del .gyp\
&& mv /var/app/node_modules /node_modules \
&& rm -rf /var/cache/apk/* \
&& apk del git
# Bundle app source
COPY . .
#COPY entrypoint.sh entrypoint.sh
# Expose port
EXPOSE 88
#ENTRYPOINT ["./entrypoint.sh"]
CMD ["npm", "run", "dev"]
This is the error i am getting:
Step 5/8 : RUN apk install git && npm i && apk del .gyp && mv /var/app/node_modules /node_modules && rm -rf /var/cache/apk/* && apk del git
---> Running in 251259cdb8a2
apk-tools 2.7.5, compiled for x86_64.
Then I get a bunch of text which resembles what you get if you type -help on something and then at the end i get:
This apk has coffee making abilities.
The command '/bin/sh -c apk install git && npm i && apk del .gyp && mv /var/app/node_modules /node_modules && rm -rf /var/cache/apk/* && apk del git' returned a non-zero code: 1
This seems to be the problematic part:
RUN apk install git \
&& npm i \
&& apk del .gyp\
&& mv /var/app/node_modules /node_modules \
&& rm -rf /var/cache/apk/* \
&& apk del git
Just try adding an additional line before using apk and see if it fixes
RUN echo "ipv6" >> /etc/modules
RUN apk install git \
Reference: link
Note: Breaking the problematic step into multiple steps like
RUN apk install git
RUN npm i
RUN apk del .gyp
RUN mv /var/app/node_modules /node_modules
RUN rm -rf /var/cache/apk/*
RUN apk del git
will help to locate the point of problem more accurately.
You have 2 issues. One is with the command apk del .gyp (which return code is different from 0) , and the other is related to the fact that you do not mount correctly your folder.
# apk del .gyp
# echo $?
1
Besides, there is no such thing as /var/app/node_modules mounted in the container:
# ls /var/app/node_modules
# ls: /var/app/node_modules: No such file or directory
What you would do, is
Make sure you mount correctly /var/app/node_modules in the container
I am not sure what the command apk del .gyp is doing, but you may need to investigate it. It does not seems to work properly.

Resources