Caddy works with Railway

It’s been a long time since I’ve posted. I found a new service.

Railway can build and deploy using Dockerfile like Google Cloud Run and

There is a great official Caddy Docker.

FROM caddy:alpine
COPY ./public/ /srv
COPY ./Caddyfile /etc/caddy/Caddyfile

Get the port number from the environment variable PORT.
You can also add custom domains on Railway and add them here.


root * /srv

All you have to do is put index.html etc. in the public directory. Easy!


I prepared a template so that you can easily use Caddy on Railway. It has the source on GitHub.

You can easily create a project with the Deploy on Railway button. Don’t worry, you can try it for free.

Railway already had an nginx template, so we would be happy if Caddy was chosen instead.


FYI, we recommend to put your static files in /srv or /var/www/html.

/usr/share/caddy is a “system directory” for Caddy for it to store some extra files it needs by default (e.g. default index.html) but that shouldn’t get modified or used by users in general.

1 Like
FYI, we recommend to put your static files in /srv or /var/www/html.

Since /srv is often used by Docker images (like /opt in distributions)
I believe /var/www/html was the webroot that the distributions adopted.
This will be a Docker environment to use together or a personal preference.
(In my case, I prefer to put it in /home unless I’m in a Docker environment, or in Dropbox)

I’m copying to /usr/share/caddy because that’s the default behavior
and I wanted to keep the Dockerfile as simple as possible.

Other web server Docker image is also in /usr, so this is common,
The PHP Docker image defaulted to /var/www/html.

Actually the default WORKDIR in our Docker image is /srv so if you omit root in your config, that’s where it’ll serve from. Hence why we recommend it.

that? The webroot for the Caddy Docker image is /usr/share/caddy

and - Basic Usage

I’m currently missing a Caddyfile in my GitHub project. It uses default settings.

The reason I originally put the Caddyfile in was that I needed to get the port number from the environment variable PORT.
However, even when I put sed in the Dockerfile, it didn’t seem to work.
That’s why I included the PORT in the Caddyfile.

You can set the environment variable PORT manually, but it can be set after deploying once, so you will see One Moment or Application Error once the first time. I needed to clear up that confusion of yours.

Railway is slow to boot if it is a trial. After the URL is displayed, it takes time to get a normal display. If you use these, you should wait patiently. I was getting trouble with it initially when I used Railway.

I’m talking about this line:

The default Caddyfile is just so that you can see the welcome page. Users should not put their files in the same place.

This is exactly how Apache does it as well. It puts its welcome page in /usr/share (I don’t have the exact path handy) and they recommend /var/www and such iirc.

We recommend /srv as a modern and easy to type location.

If so, shouldn’t the Basic Usage in the document be changed because it’s not a recommended usage? Because I’m posting non-recommended information from the past! (That’s when Caddy Docker was first released!)
However, since the topic is too different from the original post, please separate it and work on discussion etc. if necessary.

But I am getting the correct comment. I should consider changing the (web) root of this original post. However, other Dockers are also affected, so it may take a few days.

I updated the original post. In this explanation, displaying static files is enough for the purpose, so I changed it to put static files in /srv.

WORKDIR is treated like the current directory, so if you’ve read this far, you’ll understand that your Dockerfile will work with:

FROM caddy:alpine
COPY ./public/ .
COPY ./Caddyfile /etc/caddy/Caddyfile

I also updated the GitHub project accordingly.
Somewhere I’ve published a procedure using Caddy Docker, so I need to rewrite it. We will do it sequentially.

1 Like

This topic was automatically closed after 14 days. New replies are no longer allowed.