I just started learning docker a couple of weeks ago and I’ve been able to do a few things.
Right now I’m trying to create a simple Express API with mongo and a couple of static HTML files to display the data from the API endpoints. The issue I’m facing is that when I try to set the static HTML pages to a volume in the nginx service I keep getting 404 Not Found.
The express api has two endpoints and I can get there without issues either in the browser or postman, but I keep getting a 404 when I try to navigate to either index.html or values.html.
I don’t know if it’d be useful but this is the default.conf file:
upstream api {
server api:5000;
}
server {
listen 80;
location /api {
proxy_pass http://api;
}
}
Well … I’m not 100% sure about the behavior of docker-compose … but Afaik, if both containers want/need to access the same data, they both need to share the same volume.
In other words: Your first container has the static pages. In order to have them accessible by the second container, it’ll need to create a volume (e.g.) “static-pages” and link it to the path were the files reside
Now, the second container also needs this volume to get access to this files.
I don’t have much experience with docker-compose so volume handling might be different here … but I’d suggest try something like this:
Thanks for the answer, but it didn’t work. The API keeps working though.
Shouldn’t the API service not care about the static HTML files? After all the only purpose is to provide endpoints to get data from a database. The static HTML files contains the JS code to make the requests to the express API, but the express server is not serving any static files at all.