skip to Main Content

I’m trying to build a Dockerfile with below content:

FROM openjdk:8-jdk-alpine

# working directory 
WORKDIR /opt

# create directory for gatling install
RUN mkdir -p dir

# install
RUN apk add --update wget bash libc6-compat && 
mkdir -p /tmp/downloads && 
wget -q -O /tmp/downloads/file.zip https://repo1.maven.org/maven2/file.zip && 
mkdir -p /tmp/archive && 
cd /tmp/archive && 
unzip /tmp/downloads/file.zip && 
mv /tmp/archive/file/* /opt/file/ && 
rm -rf /tmp/*

# change context to file directory
WORKDIR  /opt/file

# set directories below to be mountable from host
VOLUME ["/opt/file/conf", "/opt/file/results", "/opt/file/user-files"]

# set environment variables
ENV PATH /opt/path
ENV HOME /opt/HOME

ENTRYPOINT ["execScript.sh"]

When I run this command : sudo docker build -t tag:name . I got below error as:

ERROR: failed to solve: process "RUN apk add --update wget bash libc6-compat && 
mkdir ..." did not complete successfully: exit code: 139

I’m using Mac M1 Apple chip, arm64. How do I resolve this issue?

Edited: I tweak a bit by adding RUN to each line, it turns out that the faulty line was wget -q -O /tmp/downloads/file.zip https://repo1.maven.org/maven2/file.zip, logging was:

Dockerfile:22
--------------------
  20 |     RUN apk add --update wget bash libc6-compat
  21 |     RUN mkdir -p /tmp/downloads 
  22 | >>> RUN wget -q -O /tmp/downloads/file.zip https://repo1.maven.org/maven2/file.zip
  23 |     RUN mkdir -p /tmp/archive 
  24 |     RUN cd /tmp/archive
--------------------
ERROR: failed to solve: process "/bin/sh -c wget -q -O /tmp/downloads/file.zip https://repo1.maven.org/maven2/file.zip" did not complete successfully: exit code: 139

Further debugging by jumping directly to docker using docker exec -it id sh, I get this error when re-run the whole command:

/bin/sh -c wget -q -O /tmp/downloads/file.zip https://repo1.maven.org/maven2/file.zip

Turns out that wget cannot detect whole part -q -O /tmp/downloads/file.zip https://repo1.maven.org/maven2/file.zip in its command, I have tried to put this wget command into double ticks, but no use.
How do I disable /bin/sh -c ?

2

Answers


  1. Chosen as BEST ANSWER

    It turns out that the problem comes from using Mac Apple chip, changed to a Window PC using same Dockerfile built with no issue. Only updated openjdk:19-alpine, but 8-alpine still works!


  2. You have a spaces after the slashes, remove them.

    UPDATE: was checking with mobile and it showed space after the && on the line endings, this is a common mistake that results in this kind of error.

    Checking on desktop I see no space and any problem with the commands but it is better to start with separate RUN commands so you can identify the specific command that is erroring, so in your case you should start with

    RUN apk add --update wget bash libc6-compat
    RUN mkdir -p /tmp/downloads
    RUN wget -q -O /tmp/downloads/file.zip https://repo1.maven.org/maven2/file.zip
    RUN mkdir -p /tmp/archive
    RUN cd /tmp/archive && unzip /tmp/downloads/file.zip
    RUN mv /tmp/archive/file/* /opt/file/
    RUN rm -rf /tmp/*
    

    And if all is good then concatenate the commands.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search