3

I have a docker file which contains a line like this

FROM ubuntu:14.04
RUN curl -Lso serf.zip https://URL/serf.zip \ 
&& unzip serf.zip -d /bin \
&& rm serf.zip

And that means it downloads a file and extract it within the linux image (here it is an Ubuntu-14.04).

Now, I don't want to use that URL. Instead I have the file on my local (host) machine which is a Ubuntu-12.04. The question is, how can I transfer the file from the host OS to the docker image? Then, I am able to change the Dockerfile to

FROM ubuntu:14.04
RUN unzip serf.zip -d /bin \
&& rm serf.zip

?

P.S: Currently, I have the following images

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>              <none>              99ca37acd529        39 hours ago        261.2 MB
data-analytics      dataset             1db2326dc82b        2 days ago          1.742 GB
ubuntu              14.04               780bd4494e2f        4 weeks ago         187.9 MB

2 Answers 2

7
FROM whatever
COPY contextfile containerfile
RUN do_thing_to containerfile

in your case

FROM ubuntu:14.04
COPY serf.zip serf.zip
RUN unzip serf.zip -d /bin \
&& rm serf.zip
  1. The file must be in the build context. Conventionally, that means it's in the directory or a subdirectory below the directory containing the Dockerfile.
  2. You will either have to create a layer just container the newly copied file, or use ADD magic to automatically uncompress it. Both approaches have their drawbacks.
Sign up to request clarification or add additional context in comments.

2 Comments

I would suggest ADD as it will also extract the file (hence avoiding one RUN and its two commands).
I did mention ADD, but Dockerfile best practices recommend against it. See the link in my answer for more details.
1

If you're ok having the file under the same directory (or subdirectories) of your Dockerfile, you can use COPY.

ADD will unzip it for you at the same time, removing the need for unzip and rm.

Now if you want to share the serf.zip file between projects, links won't do, you need to bind mount it on the host before running docker build:

sudo mount --bind /path/to/serf.zip_folder /path/to/Dockefile_folder

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.