Skip to content

orianna-zzo/hugo-docker-dev

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hugo-docker-dev

Docker image for Hugo development environment.

You can build static sites generated by Hugo with this docker image. The development environment dependencies are defined in the docker image, and the site's files and data are stored in the local disk in the host. Any changes in the directory of {content, layouts, static, themes} will be directly reflected in the static sites.

The directory structure of the site is as follows:

.
└── site
    ├── config.toml / config.yaml / config.json
    ├── content
    │   └── ...
    ├── layouts
    │   └── ...
    ├── themes
    │   └── ...
    ├── static
    │   └── ...
    ├── archetypes
    │   └── ...
    ├── data
    │   └── ...
    └── ...

Please check the official website for more information about Hugo!

Get the Image

There are two ways to get the docker image. One is to pull it from docker hub, the other is to build it by yourself.

From Docker Hub

Here is the image on the Docker Hub. The compressed size is only 32MB. You can simply pull the latest image by:

$ docker pull orianna/hugo

Check the image, and this image is only 85.3MB now:

$ docker images

Build the Image

If you have pulled the image from Docker Hub, you can skip this part.

Check HUGO_VERSION in the Dockfile compared to Hugo. Modify HUGO_VERSION if it is not the latest version.

Go to the repo's root and open the terminal:

$ docker build -t your/image-name:your-tag -t your/image-name:latest .

-t tags the image and one image can be tagged several times.

your/image-name is formatted by docker hub. It is not the official image so you have to put your docker cloud name before the slash.

. means from this directory.

e.g.

$ docker build -t orianna/hugo-docker-dev:0.1 -t orianna/hugo-docker-dev:latest .

Check the image, and this image is only 94.0MB now:

$ docker images

Run the Container

Run the docker container:

$ docker run --name container-name -v your-site-source-path:/hugo-site -v your-static-site-path:/static-site -p 1313:1313 --rm -it your/image-name:your-tag [command] [flags]

--name defines the name of the container.

-v mounts the local directory to the docker.

-p defines the port mapping.

--rm means the container created by the command will be removed after the container is stopped.

-i means interactive.

-t means to open a terminal.

-v your-site-source-path:/hugo-site mounts your local Hugo source to the docker. -v your-static-site-path:/static-site defines where to save the static sites generated by Hugo, which can be omitted if you only want to test your source on the server or if you generat the static sites without -d flag.

e.g.

$ docker run --name my-hugo -v $(pwd)/site-sample:/hugo-site -v $(pwd)/public:/static-site -p 1313:1313 --rm -it orianna/hugo:latest

To simplify it, you can config alias in ~/.profile as follows:

alias hugo="docker run -it --rm -v \$(pwd)/site-sample:/hugo-site -v $(pwd)/public:/static-site -p 1313:1313 orianna/hugo:latest"

With this alias, you can use the dart-sass image as if you use hugo command locally:

$ hugo version                      
$ hugo -h                      

If you want to use shell in the container interactively, you can enter:

$ docker run --name my-hugo -v $(pwd)/site-sample:/hugo-site -v $(pwd)/public:/static-site -p 1313:1313 --rm -it --entrypoint sh orianna/hugo:latest

Tag Version

v0.46: == latest

Hugo: v0.46. Alpine: v3.8