Featured image of post Hugo Dockerfile

Hugo Dockerfile

A Dockerfile to create a container image for the Hugo web framework

A basic version of a Hugo docker container

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
FROM ubuntu:latest

# Update the package list and install necessary dependencies
RUN apt-get update && apt-get install -y \
    wget \
    curl \
    unzip \
    git \
    && rm -rf /var/lib/apt/lists/*

# Define Hugo version (you can change this)   
ARG HUGO_VERSION=0.145.0

# Download and install Hugo
RUN wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_Linux-amd64.deb \
    && dpkg -i hugo_extended_${HUGO_VERSION}_Linux-amd64.deb \
    && rm hugo_extended_${HUGO_VERSION}_Linux-amd64.deb

# Verify Hugo installation
RUN hugo version

# Set the working directory (optional)
WORKDIR /app/

# Expose the Hugo port (optional)
EXPOSE 1313

# Define the default command (optional)
CMD ["hugo", "server", "-D", "-b", "http://0.0.0.0/", "--bind=0.0.0.0", "--port=1313"]

# Or a simple bash shell
#CMD ["/bin/bash"]

Can be used with docker-compose

1
2
3
4
5
6
7
services:
    my-hugo-server:
        ports:
            - 1313:1313
        volumes:
            - ./my-new-site:/app
        image: my-hugo-server:latest

Also a good reference

https://github.com/panubo/docker-hugo

Built with Hugo
Theme Stack designed by Jimmy