Skip to content

Commit 87fab84

Browse files
committed
Fix SIGINT problem in Docker image
1 parent 4e6055f commit 87fab84

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
FROM ubuntu AS builder
1+
FROM yhirose4dockerhub/ubuntu-builder AS builder
22
WORKDIR /build
33
COPY httplib.h .
44
COPY docker/main.cc .
5-
RUN apt update && apt install g++ -y
65
RUN g++ -std=c++23 -static -o server -O2 -I. -DCPPHTTPLIB_USE_POLL main.cc && strip server
76

87
FROM scratch

docker/main.cc

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ constexpr auto error_html = R"(<html>
2323
</html>
2424
)";
2525

26+
void sigint_handler(int s) { exit(1); }
27+
2628
std::string time_local() {
2729
auto p = std::chrono::system_clock::now();
2830
auto t = std::chrono::system_clock::to_time_t(p);
@@ -49,6 +51,8 @@ std::string log(auto &req, auto &res) {
4951
}
5052

5153
int main(int argc, const char **argv) {
54+
signal(SIGINT, sigint_handler);
55+
5256
auto base_dir = "./html";
5357
auto host = "0.0.0.0";
5458
auto port = 80;

0 commit comments

Comments
 (0)