余尚辉 1 month ago
parent
commit
07c6084159
2 changed files with 7 additions and 7 deletions
  1. 6 6
      docker-compose.yml
  2. 1 1
      server.js

+ 6 - 6
docker-compose.yml

@@ -1,16 +1,16 @@
-version: '3.8'
+version: '3'
 
 services:
   log-server:
-    build: .
     ports:
-      - "3006:3006"  # 将容器的 3006 端口映射到主机的 3006 端口
+      - "3006:3006"  # 将容器的 3000 端口映射到主机的 3000 端口
+    container_name: log-server
+    image: log-server:latest
     environment:
       - NODE_ENV=production
-    restart: always  # 容器崩溃后自动重启
-    # 删除 container_name,这样 Docker 会自动为每个容器生成唯一名称
     deploy:
       resources:
         limits:
           cpus: "1.0"  # 每个容器最多使用 1 个 CPU 核心
-          memory: 1G    # 每个容器最多使用 1GB 内存
+          memory: 1G   # 每个容器最多使用 1GB 内存
+    restart: always  # 容器崩溃后自动重启

+ 1 - 1
server.js

@@ -16,7 +16,7 @@ app.post('/log', (req, res) => {
 });
 
 // 启动服务,监听 3000 端口
-const PORT = 3000;
+const PORT = 3006;
 app.listen(PORT, () => {
   console.log(`Server running on http://localhost:${PORT}`);
 });