How to make wget run in docker

Hi 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 be executed, I have tried to put this wget command into double ticks, but no use.
How do I disable /bin/sh -c OR is there any workaround I can do ?

What’s the result of

docker exec -it <c-id> wget 

?

Either wget is not installed or not in path.

Does it work with curl?

The base image openjdk:8-jdk-alpine already has a wget, so adding it again should not be necessary. Try changing the RUN line as follows:

RUN apk add --update 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/*

It should work.

Please do not use this image. It has a deprication notice.

The tag 8-jdk-alpine was release 5 years ago, and has critical and high vulnerabilities according Synk:

  • 3 critical
  • 14 high
  • 34 medium
  • 36 low

You might want to replace it with eclipse-temurin:8-jdk. If you start your project on green field, you should definitely start with Java 21, otherwise you start with technical debts for the migration to Java 21 from the get go.

It turns out that the problem comes from using MAC M1 Apple Chip !!!
Upgraded to openjdk:19-alpine and things work normally now, with the same Dockerfile content.

hi @meyay I would not mind changing to new java, could you recommend some equivalent package manager to apk ?
Thank you for suggestion

If you use the alpine “flavour” of the eclipse-temurin images, you can continue to use apk. For example, you could use eclipse-temurin:21.0.2_13-jdk-alpine. This should work on M1 Apple chip also.

yo thanks for reminding me about this topic.

Yeah you can go with openjdk:11-jdk-alpine (there may be some distinct problem as I recall), but it is recommended as you should go with java 21 if you were to start fresh