Goal
I would like to compile an Crow Project with CMake and deploy it in a docker container.
Code
So far, I compiled in Visual Studio and installed Crow via VCPKG similar to this Tutorial. example main.cpp from Crow website:
#include "crow.h"
//#include "crow_all.h"
int main()
{
crow::SimpleApp app; //define your crow application
//define your endpoint at the root directory
CROW_ROUTE(app, "/")([](){
return "Hello world";
});
//set the port, set the app to run on multiple threads, and run the app
app.port(18080).multithreaded().run();
}
I want to build my docker image with docker build -t main_app:1 .
and then run a container with docker run -d -it -p 443:18080 --name app main_app:1
.
Therefore, I considered something similar like this:
Dockerfile:
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get upgrade -y
# is it necessary to install all of them?
RUN apt-get install -y g++ gcc cmake make git gdb pkg-config
RUN git clone --depth 1 https://github.com/microsoft/vcpkg
RUN ./vcpkg/bootstrap-vcpkg.sh
RUN /vcpkg/vcpkg install crow
CMakeLists.txt:
cmake_minimum_required(VERSION 3.8)
project(project_name)
include(/vcpkg/scripts/buildsystems/vcpkg.cmake)
find_package(Crow CONFIG REQUIRED)
add_executable(exe_name "main.cpp")
target_link_libraries(exe_name PUBLIC Crow::Crow)
Questions
- However, obviously this is not complete and thus will not work. Hence, I would like to know how a proper (and simple) Dockerfile and CMakeLists.txt would look like for this main.cpp?
- Is it possible to create my image without VCPKG? I am a little bit concerned about my image and container size, here.
- How would it work with the
crow_all.h
header only file? - Is it possible to build an image from an already compiled name.exe, as well - so I won't have to compile anything while building the image?
- Since this ought to be a minimal example, would there be any conflicts with a file structure like this:
docker_project
|__Dockerfile
|__CMakeLists.txt
|__header.hpp
|__class.cpp
|__main.cpp
Thanks for your help :)