You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Docker Compose在API镜像中访问其他镜像的public文件夹

问题分析与解决

你当前的挂载配置存在冲突:API服务的volumes里,./server:/app已经把本地server目录挂载到容器的/app目录,紧接着又挂载./client/public:/app,这会直接覆盖容器内的/app目录——原本的server代码被替换成client的public内容,不仅API服务可能无法正常运行,也达不到同时访问server代码和client public文件的目的。

正确的挂载方式

把client的public目录挂载到API容器内/app的子目录,比如/app/client-public,这样既保留server代码,又能访问到client的public文件。修改后的Compose文件如下:

version: '3'
services:
  api:
    restart: always
    build:
      dockerfile: Dockerfile.dev
      context: ./server
    volumes:
      - /app/node_modules
      - ./server:/app
      - ./client/public:/app/client-public
    ports:
      - '5000:5000'
  client:
    build:
      dockerfile: Dockerfile.dev
      context: ./client
    volumes:
      - /app/node_modules
      - ./client:/app
    links:
      - api

之后在API代码里,直接通过/app/client-public这个路径就能访问client public文件夹里的所有文件了。

内容的提问来源于stack exchange,提问作者Konya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 11:28:06