In this article, I will summarize the procedure for creating a virtual environment for running Hugo (static site generator) with Docker.
VS Code installation Reference: Introduction to Docker with VS Code
In order to create a virtual environment with Docker, it is necessary to create
docker-compose.yml. It is necessary to describe the image to be used (material that creates the virtual environment) and detailed settings in this file. Docker Hub is a Docker image storage area.
When building an environment with Docker, check if there is an image that can already be used
On Hugo's official website, I searched with Docker and found an image recommended by the official, so use the following. https://hub.docker.com/r/klakegg/hugo/
docker-compose.yml based on the following sample described in klakegg / hugo
In this article, the goal is to hit the "hugo" command in a virtual environment, so I wrote it as follows. The reason for selecting the image is shown at the bottom.
version: '3' services: hugo: image: klakegg/hugo:0.74.3-ubuntu volumes: - ".:/src" entrypoint: bash ports: - "1313:1313" tty: true working_dir: /src
About each tag
version: '3' #The latest version is'3' services: #Fixed servicename: #Give the name of any service image:Image name:Tag name#Specify the image to be used from Docker Hub volumes: -Local folder path:Container folder path#Linking local and virtual machine folders entrypoint:processing# entrypoint:Described when you want to overwrite the default entry point ports: #Because I want to run "hugo server" - "Host side: Container side" tty: true #Required when entering a container with Attach Shell working_dir:Container folder path#Working directory in the container
By using "hugo server", you can check the screen created by hugo. Therefore, port 1313 is used by default, but in order to use the server started on the container side locally, it is necessary to connect the local and container ports.
Make sure Docker is running and run the following command
docker-compose up -d
Container creation is complete! Click Attach Shell to enter the container you created Type "hugo version" and it's OK if the hugo version is returned
klakegg / hugo: 0.74.3-ubuntu
Initially, I was considering using [Hugo 0.74.3: 0.74.3] in [Default minimal image based upon ** Busybox **:], but I couldn't use the "bash" command. Therefore, I adopted [hugo: 0.74.3-ubuntu] which can use this command. The process leading up to the change is shown below.
In Hugo 0.74.3, hugo is called with ENTRYPOINT. I want to execute the "hugo" command at any time, not at startup
Overwrite the image entrypoint by writing
entrypoint: bash and do nothing at startup.
version: '3' services: hugo: image: klakegg/hugo:0.74.3 volumes: - ".:/src" entrypoint: bash ports: - "1313:1313" tty: true working_dir: /src
Execute the virtual environment construction command. Execute the following command in the docker-compose.yml folder
docker-compose up -d
An error has occurred and the container cannot be created.
You can't use the
bash command with the default
Therefore, we adopted
klakegg / hugo: 0.74.3-ubuntu which can use the
I explained how to write docker-compose.yml Overview of Docker Hub Compose File Reference