sveltekit adapter-node docker volume issue serving updated static files after build time

24 Views Asked by At

I work on a sveltekit app which is run in docker in production environment.

I need to serve some "static" files uploaded from another server to production server and serve them from my app. Ok, they are not so static because they can change and are not in place at build time!

I thought it would be obvious to create a docker volume between host static folder and /app/static in node container. But I get a 404 error when accessing files in static folder when those were not in this folder at build time.

Here is my docker-compose.yaml not working:

version: '3.3'

services:
  mymy:
    image: 3151/mymy
    build:
      context: .
      dockerfile: ./Dockerfile
    ports:
      - '${APP_PORT}:3000'
    restart: always
    networks:
      net1:
        ipv4_address: ${MY_IPV4_ADDRESS}
    volumes:
      - ./static:/app/static

networks:
  net1:
    name: ${DB_NETWORK_NAME}
    external: true

See what I tried in volumes section.

Here is the Dockerfile by the way:

FROM node:lts-slim

WORKDIR /app

COPY ./package.json package.json
COPY ./package-lock.json package-lock.json
COPY ./src src
# COPY ./static static
COPY ./svelte.config.js svelte.config.js
COPY ./tsconfig.json ./.svelte-kit/tsconfig.json

COPY ./vite.config.ts vite.config.ts
COPY ./.env .env

RUN npm ci
RUN npm run build

EXPOSE 3000

CMD [ "node", "build" ]

I commented out COPY ./static static since I wanted it to be a docker volume.

When I launch docker-compose up --build, this url works fine: http://10.5.0.72:3000/robots.txt

(robots.txt is in static folder at build time.)

If I add test.txt in static folder when app is running, http://10.5.0.72:3000/test.txt returns a 404...

All I need is an idea to rsync files from outside my app and serve them. What can I try next?

0

There are 0 best solutions below