I have a C++ application which depends on several other third party projects which I clone and build from source. I wanted to now deploy this application as a docker container. Consider following directory structure
workspace├── dependency-project-1| ├── lib| ├── build| ├── include| ├── src| └── Thirdparty| ├── sub-dependency-project-1| | ├── lib| | ├── build| | ├── include| | ├── src| | └── CMakeLists.txt| └── sub-dependency-project-N├── dependency-project-N (with similar structure as dependency-project-1)└── main-project (with similar structure as dependency-project-1 and depedent on dependency projects above)
Those build
and lib
folders are created when I built those projects with cmake
and make
. I used to run app from workspace/main-project/build/MyApp
For deployment, I felt that I will create two stage dockerfile. In one stage I will build all the projects and in second stage I will only copy build
folder from first stage. The build was successful. But while running the app from the container, it gave following error:
./MyApp: error while loading shared libraries: dependency-project-1.so: cannot open shared object file: No such file or directory
This .so
file was in workspace/dependency-project-1/lib
folder which I did not copy in second stage of dockerfile.
Now I am thinking how can gather all build artefacts (build
, lib
and all other build output from all dependency projects and their sub-dependency projects) into one location and then copy them to final image in the second stage of the dockerfile.
I tried to run make DESTDIR=/workspace/install install
inside workspace/main-project/build
in the hope that it will gather all the dependencies in the /workspace/install
folder. But it does not seem to have done that. I could not find MyApp
in this directory.
What is standard solution to this scenarion?