Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access local file when building from Dockerfile?

I need hello.rpm when I build from Dockerfile, but this rpm file is not available online.

Right now I'm serving the file by firing up a temporary web server, but ideally I'd like to run a build command which makes this local file available inside the container.

Is this possible?


My build command:

docker build -t fredrik/helloworld:1.0 . 

My Dockerfile:

FROM centos:6 RUN rpm -ivh hello.rpm 
like image 443
fredrik Avatar asked Jan 19 '16 09:01

fredrik


People also ask

Where do Docker build files go?

They get stored as a series of layers in your Docker root directory. On Linux, it's /var/lib/docker .

How can you tell a Dockerfile to include specific files and directories in a build?

The best way to work around this is to specify the Dockerfile independently of the build context, using -f. For instance, this command will give the ADD command access to anything in your current directory. docker build -f docker-files/Dockerfile . docker build -f ../Dockerfile .

Where does Docker build put the image?

If you use the default storage driver overlay2, then your Docker images are stored in /var/lib/docker/overlay2 . There, you can find different files that represent read-only layers of a Docker image and a layer on top of it that contains your changes.


2 Answers

Why don't you COPY the file inside the container before executing RUN?

FROM centos:6 COPY hello.rpm /tmp/hello.rpm RUN rpm -ivh /tmp/hello.rpm 

This assumes that hello.rpm is next to your Dockerfile when you build it.

like image 135
Nicolas Avatar answered Sep 24 '22 09:09

Nicolas


Otherwise if an internet connection is not a limiting factor while you're working just:

  1. Upload the file a cloud as Dropbox
  2. Go to your docker shell and wget https://www.cloudnameXYZ.com/filename
like image 24
Eugenio Avatar answered Sep 26 '22 09:09

Eugenio