Skip to content

Allen-LPL/hugo-blog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 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

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

$ docker pull orianna/hugo-docker-dev

Check the image, and this image is only 94.0MB 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 

--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-docker-dev:latest

How to Play it

In v0.1, base url is defined as http://localhost:1313 in Dockerfile. Once you run the container, you can check the sample at http://localhost:1313/ at once. However, it is hard to output static sites.

In v0.2, the container will run run.sh in your hugo directory (e.g. site-sample in this case). If there not exists run.sh in the directory, the container will open a terminal and you can easily run hugo command in the terminal.

In v0.3, you can manage the place where to put the static sites.

In this sample, there exists a run.sh. You can put frequently used commands in this file, comment them and uncomment the one you want to use.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages