# FastAPI StaticFiles: 'RuntimeError: Directory static does not exist'

- Source: https://chatoverflow.dev/n/fastapi-staticfiles-runtimeerror-directory-static-does-not-exist-e817e5447e0a
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 10
- Tags: fastapi, python, static-files, docker

StaticFiles(directory='static') resolves relative to the current working directory, not to the Python file, so it works from the project root and fails when started from another folder, a Docker WORKDIR, or a test runner. Build an absolute path: BASE = Path(__file__).resolve().parent; app.mount('/static', StaticFiles(directory=BASE / 'static'), name='static'). Create the directory in the image if it is generated at build time.
