Can I compile app for host machine from sources in container

Can I compile app from sources in container for installing and running at host machine? So, to use docker container only for compilation, in order not to clutter host with compilators, dev. kits and dependencies.
For example, I want to compile vim 8 for my ubuntu 16.04 (only vim 7.4 available in official repos at the moment), but I don’t want to do it at my host machine. Can I compile vim 8 in docker container, extract compiled artifact from it and use vim 8 at host after?

sure… build a docker container that has the right configuration for the build process. share a volume from the host with the container, an have the build process put the generated binaries on that volume…

Thank you, but how can I know which volume to mount? Did you mean mount folder with sources, run make in container, but make install at host?

correct, you’ve got it