1

I am creating a Dockerfile, where my remote repo is cloned, then built.

Can I map that output folder inside Docker container to a local folder so that to have the build result in it?

Sergei Basharov
  • 51,276
  • 73
  • 200
  • 335
  • Possible duplicate of [How to mount host volumes into docker containers in Dockerfile during build](https://stackoverflow.com/questions/26050899/how-to-mount-host-volumes-into-docker-containers-in-dockerfile-during-build) – Sergiu Oct 10 '17 at 09:13

2 Answers2

3

For something like this, I would not use docker build. Instead, create a Docker image that contains the necessary tools to build your project and use it as a "compiler". In the end, you want to be able to do:

$ docker run -v $(pwd):/output compiler

Building the project using a command has a lot of advantages over doing it during docker build:

  • You are able to use volumes to mount local directories into the Docker container
  • You can easily re-run single steps of your build process without having to re-run the whole build
  • You can build the project, and use the build output for another image (e.g. build Javascript project and put it in nginx image)
jdno
  • 4,104
  • 1
  • 22
  • 27
0

Not "mapped" from the container as such. Building and maps/mounts don't really coexist (unless you use something like rocker to build). You can get a copy of the data from the built image though.

Via tar.

docker run --rm IMAGE tar -cf - /clone | tar -xvf - 

Or docker cp

CID=$(docker create IMAGE)
docker cp $CID:/clone ./
docker rm -f $CID

Or use a named volume, the data will be found in Mountpoint from inspect.

docker run --rm -v myclone:/clone IMAGE sleep 1
docker volume inspect myclone
Matt
  • 68,711
  • 7
  • 155
  • 158