Docker + Subdirectory

I want to use the Docker installation rather than manual installation (docker-compose image works fine, no problem accessing it under port 3000) but I want to change CodiMD’s web installation folder from root to a subdir, i.e. from http://localhost:3000/ to http://localhost:3000/codimd – is that possible? Any pointers?

Right now I notice the html content points to absolute urls such as <img src="/screenshot.png" /> .

I take it I’d need to edit the docker image to change the internal web server’s config to serve the static files at the /codimd url instead of at /, and then also set CMD_URL_PATH=codimd in the docker env variables.

  • Setting only CMD_URL_PATH=codimd does changes the html output of localhost:3000/ and shows broken images and css, there is nothing at localhost:3000/codimd

  • Setting only CMD_URL_PATH=codimd and also changing app.js to read app.use('/codimd', express.static(path.join(__dirname, '/public'), { maxAge: config.staticCacheTime, index: false })) ends up in a redirect loop between /codimd/ and /codimd` (not the missing trailing slash)

I’d be grateful for some more exact pointers on how to do this.

The end goal is to put the CodiMD docker under a proxypass such that mydomain.com/codimd proxy-passes to localhost:3000/codimd (I can do a few things by rewriting html output, but that’s not cutting it, as some CSS would also need to, it would be just cleaner to have CodiMD installed in a web subdir)

(small housekeeping notice: I moved this question into its own topic, this way it will probably get more attention and it can be resolved once it’s achieved. Feel free to change the topic name, my attempt may be a bit short)

1 Like

Thank you. Your forum did not allow me to create a new topic, hence I had to find an existing topic to post as a reply …

This should be solved with the latest stable version 1.6.0 which you can get from https://quay.io/repository/codimd/server

Thanks to some contributors this feature was fixed in 1.6.0. If you are already running 1.6.0 and it’s an issue, it would help a lot when you share your config (of course without secrets) to have us reproducing the issue.

That is great to hear, but how exactly do I configure the Docker image to achieve my goal of serving web files from /codimd instead of /? Just adding CMD_URL_PATH=codimd wouldn’t be enough. I’d be grateful for some specific instructions.

Do you run a reverse-proxy between CodiMD and the User? Because this parameter will only adjust the path in the frontend, not in the backend.

the nginx config should be a bit like:

location /codimd/ {
  # if you don't want to pass /codimd/ add a trailing slash to the proxy_pass
  proxy_pass http://localhost:3000/;

  ...
}

Modified version of https://stackoverflow.com/a/51326840

CodiMD will not serve files from a subdirectory locally.

Yes, as I said, the idea is to use a reverse-proxy so i can access CodiMD at https://domain.com/codimd.

I use Apache, not Nginx. Regardless, your example won’t work if CodiMD does not serve files from a subdirectory, because the links in the html, css, js will point to /.

Do you have a working version of a CodiMD deployment at a url like https://domain.com/codimd which uses the CodiMD docker image (not manual deployment). If yes, would you mind sharing the setup of the web server and Docker image?