Skip to content
Advertisement

Dockerfile – can’t unzip files using a shell script

I’m facing an issue unziping files that have been copied on a docker image. I tried using the RUN unzip /file.zip and other techniques that I came across but nothing seems to work.

So then I tried adding the unziping action into the a shell script that I use as entrypoint for my docker image.

Here is the yaml file for the build:

RUN mkdir jobs
COPY test_0.1.zip /jobs/test_0.1.zip
COPY entrypoint.sh /jobs/
RUN cd jobs/
CMD [ "/jobs/entrypoint.sh" ]

And here is the code of the shell script:

function setup()
{
echo "Preparing files for job execution"
unzip test_0.1.zip
}
setup &
b=$!
wait $b
cd test/
chmod +x test_run.sh
./test_run.sh

When I just run the container using the image I get this error:

unzip: can't open test_0.1.zip[.zip]
/jobs/entrypoint.sh: cd: line 10: can't cd to test/: No such file or directory
chmod: test_run.sh: No such file or directory
/jobs/entrypoint.sh: line 12: ./test_run.sh: not found

The unzip action doesn’t work but when I access the container in command line I can run the script and it works.

Is there a problem with my Dockerfile or my shell script, or is it something specific to docker?

Thanks for the replies and sorry if this kind of questions have already been asked and answered.

Advertisement

Answer

Replace RUN cd jobs/ with with WORKDIR /jobs/.

The RUN command will run a set of commands, but will not retain any state for future commands. So essentially, your cd jobs/ gets undone.

WORKDIR on the other hand sets that to be the working directory for future commands.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement