Dockerfile for Web services
You can also use Google Cloud Run, Fly, Railway, Dokku or CapRover.
Google Cloud Run
Fly (fly.io)
Railway
It can also be used with various Docker-based PaaS.
Table of Contents
Information by service
This page lists the port number, so you need to set it.
CapRover
Captain Definition File | CapRover Docs
Generate the following files captain-definition
to apply the Dockerfile
.
{
"schemaVersion": 2,
"dockerfilePath": "./Dockerfile"
}
You can also write the contents of Dockerfile directly in captain-definition
.
Fly
You can describe the port number in fly.toml
.
[[services]]
internal_port = 80
fly deploy
often fails in my experience. For example, the builder is not ready or wget fails. That’s not the problem with this code. If you experience that, wait a while and try fly deploy
again.
Railway
Exposing Your App | Railway Docs
Don’t be surprised if you get an application error on your first deploy.
Please re-deploy after putting PORT
in the variable. Displayed after some time from deployment.
Apache
Listen port: 80
FROM httpd:2.4
COPY ./public_html/ /usr/local/apache2/htdocs/
Caddy v2
Listen port: 80
FROM caddy:alpine
COPY ./public_html/ /srv/
RUN sed -i 's|root .*|root * /srv|' /etc/caddy/Caddyfile
If you use Caddyfile
, Add line:
COPY ./Caddyfile /etc/caddy/Caddyfile
Hugo + Caddy v2
Listen port: 80
The latest version of Hugo at the time of build is used.
FROM klakegg/hugo:onbuild AS hugo
FROM caddy:alpine
COPY --from=hugo /target/ /srv/
RUN sed -i 's|root .*|root * /srv|' /etc/caddy/Caddyfile
If you use Caddyfile
, Add line:
COPY ./Caddyfile /etc/caddy/Caddyfile
MkDocs + Caddy v2
Listen port: 80
FROM python:3-slim as mkdocs
COPY ./ ./
RUN pip install --no-cache-dir -r requirements.txt
RUN mkdocs build
FROM caddy:alpine
COPY --from=mkdocs ./site/ /srv/
RUN sed -i 's|root .*|root * /srv|' /etc/caddy/Caddyfile
If you use Caddyfile
, Add line:
COPY ./Caddyfile /etc/caddy/Caddyfile
Line up the pip packages in requirements.txt
:
mkdocs
mkdocs-bootswatch
mkdocs-minify-plugin
nginx
Listen port: 80
FROM nginx:alpine
COPY ./public_html/ /usr/share/nginx/html/
PHP Built-in web server
Listen port: 80
Not recommended for public web
FROM php:8.1-alpine
COPY ./public_html/ ./
ENV PHP_CLI_SERVER_WORKERS="16"
CMD ["php", "-S", "0.0.0.0:80"]
PHP + Apache
Listen port: 80
FROM php:8.1-apache
COPY ./public_html/ /var/www/html/
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"