[Docker] Building an environment to use Hugo

Overview

In this article, I will summarize the procedure for creating a virtual environment for running Hugo (static site generator) with Docker.

environment

VS Code installation Reference: Introduction to Docker with VS Code

Overall picture

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. スクリーンショット 2020-10-06 17.11.13.png

procedure

Search for available images (materials for creating virtual environments (containers))

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. スクリーンショット 2020-09-15 15.24.17.png https://hub.docker.com/r/klakegg/hugo/

Create docker-compose.yml

Create docker-compose.yml based on the following sample described in klakegg / hugo スクリーンショット 2020-09-15 15.31.22.png

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.

docker-compose.yml


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

.yml:docker-compose.yml


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

Supplement about port

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. スクリーンショット 2020-09-16 11.00.52.png

Execute the virtual environment construction command

Make sure Docker is running and run the following command

docker-compose up -d

スクリーンショット 2020-09-15 16.52.57.png Container creation is complete! Click Attach Shell to enter the container you created スクリーンショット 2020-09-15 17.33.48.png Type "hugo version" and it's OK if the hugo version is returned スクリーンショット 2020-09-15 17.34.10.png

(Remarks) Reason why image is set to 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.

Checking tags on Docker hub

スクリーンショット_2020-09-15_16_32_42.png

Search for the contents of the image with [Tags] and check

スクリーンショット 2020-09-15 16.35.44.png

In Hugo 0.74.3, hugo is called with ENTRYPOINT. スクリーンショット_2020-09-15_16_35_27.png I want to execute the "hugo" command at any time, not at startup

Fix docker-compose.yml

Overwrite the image entrypoint by writing entrypoint: bash and do nothing at startup.

docker-compose.yml


version: '3'
services: 
    hugo:
        image: klakegg/hugo:0.74.3
        volumes:
            - ".:/src"
        entrypoint: bash
        ports:
            - "1313:1313"
        tty: true
        working_dir: /src

Building a virtual environment

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.

スクリーンショット 2020-09-15 16.51.53.png You can't use the bash command with the default BusyBox tag Therefore, we adopted klakegg / hugo: 0.74.3-ubuntu which can use the bash command.

reference

I explained how to write docker-compose.yml Overview of Docker Hub Compose File Reference

Recommended Posts

[Docker] Building an environment to use Hugo
[Rails] How to build an environment with Docker
I tried to build an environment using Docker (beginner)
[Artifactory] How to use Docker repository
Pass environment variables to docker container
How to install Pry after building Rails development environment with Docker
[Docker] Use environment variables in Nginx conf
Building Rails 6 and PostgreSQL environment with Docker
Migrate existing Rails 6 apps to Docker environment
Use docker in proxy environment on ubuntu 20.04.1
How to use Docker in VSCode DevContainer
Create Docker to use Edge TPU compiler
Try to use docker command without sudo.
How to use environment variables in RubyOnRails
Build an environment with Docker on AWS
Build an Ultra96v2 development environment on Docker 1
Understand in 5 minutes !! How to use Docker
How to build Rails 6 environment with Docker
Problems I was addicted to when building the digdag environment with docker
Complete roadmap for building environment up to Docker + rails6 + MySQL + bootstrap, jquery
Quick learning Java "Introduction?" Part 1 Building an environment
How to use an array for HashMap keys
Building OpenPose (Pytorch_Realtime_Multi-Person_Pose_Estimation) environment on Docker: training part
[Error resolution] Occurs when trying to build an environment for spring with docker
Rails6.0 ~ How to create an eco-friendly development environment
A memorandum when building an environment with Ruby3.0 x Rails6.1 x Docker x CentOS Stream
How to build an environment of [TypeScript + Vue + Express + MySQL] with Docker ~ Vue edition ~
How to use docker compose with NVIDIA Jetson
[Rails] Building an environment for developing web applications
How to use nginx-ingress-controller with Docker for Mac
[First team development ②] Build an environment with Docker
Docker environment construction
Introduce dotenv to Docker + Rails to manage environment variables
[Rails] How to use PostgreSQL in Vagrant environment
Temporarily move Docker environment from Mac to AWS
From building an AWS cloud environment to deploying a Spring Boot app (for beginners)
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
How to use git with the power of jgit in an environment without git commands
What to do when routing settings do not work after building Docker environment with Laravel
Let's finally use Docker: Start, stop, delete development environment
[Road _node.js_1-1] Road to build Node.js Express MySQL environment using Docker
How to use an array for a TreeMap key
How to build docker environment with Gradle for intelliJ
Build an environment of Ruby2.7.x + Rails6.0.x + MySQL8.0.x with Docker
[Docker environment] How to deal with ActiveSupport :: MessageEncryptor :: InvalidMessage
Create an E2E test environment with Docker x Cypress
Use Maven to add your favorite Java library to your environment.
Command memo to install xeyes in ubuntu docker environment
Rails6 I tried to introduce Docker to an existing application
Try to build a Java development environment using Docker
Beginners use ubuntu in windows to prepare rails environment
How to use Map
How to use rbenv
Rails Docker environment construction
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use map
The story of migrating a stray batch without an owner from EC2 to a Docker environment
How to use collection_select
Why we use Docker