Appearance
Getting started with the official Hugo Docker image
Discover the essentials of using the official Hugo Docker image, including quick start commands, image specifications, and an entrypoint script guide.
Quick start
The following commands demonstrate how to quickly get started with the official Hugo Docker image:
sh
docker pull ghcr.io/gohugoio/hugo:latest
This command pulls the latest official Hugo Docker image from the GitHub Container Registry.
sh
docker run -it -v $(pwd):/project -p 1313:1313 ghcr.io/gohugoio/hugo:latest server
This command runs the Hugo server in a Docker container, mounting the current directory to the container's /project
directory and exposing port 1313.
Image details
For more information, visit: Hugo Docker Image on GitHub
- Architectures:
amd64
,arm64
- Tags:
latest
,0.136.3
This part provides insights into the official Hugo Docker image, which supports both amd64 and arm64 architectures. It also offers various tags for versioning, including the latest
release and specific versions like 0.136.3
.
Image specifications
- Base image: Alpine Linux
- Included tools: Git, Node.js, Dart Sass
- User:
hugo
- Working directory:
/project
- Exposed port:
1313
- Entrypoint:
/entrypoint.sh
- Default command:
--help
The official Hugo Docker image is built on Alpine Linux, chosen for its minimal size and security-focused design. This lightweight base ensures efficient resource usage and faster deployments.
The image comes pre-installed with essential tools for modern web development:
- Git for version control
- Node.js for JavaScript-based build processes
- Dart Sass for advanced CSS preprocessing
A dedicated hugo
user is created within the container, enhancing security by avoiding root-level operations. The working directory is set to /project
, providing a consistent environment for your Hugo projects.
Port 1313
is exposed by default, aligning with Hugo's standard development server port. This allows for easy access to your site during development.
The image uses /entrypoint.sh
as its entrypoint, providing flexibility for custom initialization scripts. The default command --help
ensures that running the container without arguments displays Hugo's help information, aiding in proper usage.
Entrypoint script
sh
if [ -f hugo-docker-entrypoint.sh ]; then
sh hugo-docker-entrypoint.sh "$@"
exit $?
fi
if [ -f package.json ]; then
if [ ! -d node_modules ]; then
npm i
fi
fi
exec "hugo" "$@"
The entrypoint script is a crucial component of the Hugo Docker image, designed to provide flexibility and automate common tasks:
Custom entrypoint: The script first checks for a file named
hugo-docker-entrypoint.sh
in the current directory. If present, it executes this custom script, allowing users to define their own initialization processes or overrides.Node.js dependency management: If a
package.json
file is detected, the script checks for the existence of anode_modules
directory. If it's missing,npm i
is automatically run to install the necessary Node.js dependencies. This feature is particularly useful for Hugo themes or projects that rely on JavaScript packages.Hugo execution: Finally, the script executes the
hugo
command with any additional arguments passed to the container. This allows for flexible use of Hugo's various commands and options directly from the Docker run command.
This intelligent entrypoint script streamlines the development process, handling common setup tasks automatically while still providing the flexibility to customize the environment as needed.