ogbofjnr
ogbofjnr

Reputation: 2008

How to build docker image without sending context?

In our project we have project directory with docker configs and other common stuff and folder for each service. Since we use common stuff in dockerfiles we need to set context to root folder, but then docker sends all context to docker deamon, about 3 GB and it take some time, especially when it does so for each service.

Is there options to make it use my local filesystem directly? Or is there any alternative solutions for building OCI containers that don't send context?

Upvotes: 4

Views: 1006

Answers (2)

Juxuny Wu
Juxuny Wu

Reputation: 120

You can create a .dockerignore file in your project directory, and ignore some files you don't need. It will tell docker send context to docker deamon without the files listed in the .dockerignore file.

And you can also get more help from the official document here

For example, if you don't want to send the .git directory to docker deamon, you can create a .dockerignore file in your working directory, and run this command: echo '.git' >> .dockerignore.

Upvotes: 2

David Maze
David Maze

Reputation: 158977

One approach I've used in the past is to create a temporary build tree specifically for Docker. That could look something like

mkdir build/docker
cp Dockerfile build/docker
cp -a project-a/target/app_a build/docker
cp -a common/docker/etc build/docker
docker build -t me/project-a build/docker
rm -rf build/docker

Now the context directory is exactly what you need it to be, no more and no less, and your Dockerfile can probably be very simple.

(Actually when I did this, I built up the host context directory using a Makefile, and some level of build automation like this is probably necessary for this approach.)

Upvotes: 2

Related Questions