【发布时间】:2022-08-15 05:39:21
【问题描述】:
目标
我想用 CMake 编译一个 Crow 项目并将其部署在 docker 容器中。
代码
到目前为止,我在 Visual Studio 中编译并通过 VCPKG 安装了 Crow,类似于 Tutorial。 例子主文件来自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();
}
我想用docker build -t main_app:1 . 构建我的docker 映像,然后用docker run -d -it -p 443:18080 --name app main_app:1 运行一个容器。
因此,我考虑了类似的事情:
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)
问题
- 但是,显然这并不完整,因此不会起作用。因此,我想知道这个 main.cpp 的正确(简单)Dockerfile 和 CMakeLists.txt 会是什么样子?
- 是否可以在没有 VCPKG 的情况下创建我的图像?我有点担心我的图像和容器大小,在这里。
- 它如何与
crow_all.h仅标头文件一起使用? - 是否也可以从已编译的 name.exe 构建映像 - 这样我在构建映像时就不必编译任何东西了?
- 既然这应该是一个最小的例子,那么这样的文件结构会不会有任何冲突:
docker_project |__Dockerfile |__CMakeLists.txt |__header.hpp |__class.cpp |__main.cpp谢谢你的帮助 :)