Skip to content

Instantly share code, notes, and snippets.

@hkwi
Last active January 3, 2026 02:36
Show Gist options
  • Select an option

  • Save hkwi/5069073550eadfec029157bc811a2342 to your computer and use it in GitHub Desktop.

Select an option

Save hkwi/5069073550eadfec029157bc811a2342 to your computer and use it in GitHub Desktop.
nomad cluster 起動

Nomad Rocky Linux 9 Cluster (3 nodes)

This setup creates three Rocky Linux 9 containers running HashiCorp Nomad in server mode, forming a cluster.

Prerequisites

  • Docker and Docker Compose

Run

# Build images and start the cluster
docker compose up -d --build

# View cluster members
docker exec -it nomad1 nomad server members

# Open Nomad UI (if exposed): http://localhost:4646

Stop and cleanup

docker compose down -v

docker compose file を作る rockylinux9 のインスタンスを 3 つ hashicorp nomad をインストールしてクラスタ化する

version: "3.8"
services:
nomad1:
build:
context: .
dockerfile: Dockerfile.nomad
hostname: nomad1
container_name: nomad1
command:
- -retry-join=nomad2
- -retry-join=nomad3
environment:
- NOMAD_NODE_NAME=nomad1
- NOMAD_SERVER=true
- NOMAD_BOOTSTRAP_EXPECT=3
networks:
nomadnet:
ports:
- "4646:4646" # Nomad UI/API
volumes:
- nomad1_data:/var/lib/nomad
nomad2:
build:
context: .
dockerfile: Dockerfile.nomad
hostname: nomad2
container_name: nomad2
command:
- -retry-join=nomad1
- -retry-join=nomad3
environment:
- NOMAD_NODE_NAME=nomad2
- NOMAD_SERVER=true
- NOMAD_BOOTSTRAP_EXPECT=3
networks:
nomadnet:
volumes:
- nomad2_data:/var/lib/nomad
nomad3:
build:
context: .
dockerfile: Dockerfile.nomad
hostname: nomad3
container_name: nomad3
command:
- -retry-join=nomad2
- -retry-join=nomad1
environment:
- NOMAD_NODE_NAME=nomad3
- NOMAD_SERVER=true
- NOMAD_BOOTSTRAP_EXPECT=3
networks:
nomadnet:
volumes:
- nomad3_data:/var/lib/nomad
networks:
nomadnet:
driver: bridge
volumes:
nomad1_data:
nomad2_data:
nomad3_data:
# Rocky Linux 9 base with Nomad installed
FROM rockylinux:9
ARG NOMAD_VERSION=1.8.2
RUN dnf -y update
RUN dnf -y install wget unzip shadow-utils tar
RUN useradd -r -u 998 -g root -s /sbin/nologin nomad
RUN mkdir -p /opt/nomad /etc/nomad.d /var/lib/nomad
RUN cd /tmp && wget -q https://releases.hashicorp.com/nomad/${NOMAD_VERSION}/nomad_${NOMAD_VERSION}_linux_amd64.zip
RUN cd /tmp && unzip nomad_${NOMAD_VERSION}_linux_amd64.zip
RUN mv /tmp/nomad /usr/local/bin/nomad
RUN chmod +x /usr/local/bin/nomad
RUN rm -rf /tmp/*
RUN dnf -y clean all
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh && \
chown -R nomad:root /etc/nomad.d /var/lib/nomad
EXPOSE 4646 4647 4648
VOLUME ["/var/lib/nomad"]
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
#!/usr/bin/env bash
set -euo pipefail
# Defaults from environment
NODE_NAME="${NOMAD_NODE_NAME:-$(hostname)}"
IS_SERVER="${NOMAD_SERVER:-true}"
BOOTSTRAP_EXPECT="${NOMAD_BOOTSTRAP_EXPECT:-3}"
DATA_DIR="/var/lib/nomad"
CONFIG_DIR="/etc/nomad.d"
mkdir -p "$DATA_DIR" "$CONFIG_DIR"
IP_ADDR=$(hostname -i | awk '{print $1}')
cat > "$CONFIG_DIR/server.hcl" <<EOF
data_dir = "$DATA_DIR"
bind_addr = "0.0.0.0"
name = "$NODE_NAME"
log_level = "INFO"
advertise {
http = "$IP_ADDR:4646"
rpc = "$IP_ADDR:4647"
serf = "$IP_ADDR:4648"
}
server {
enabled = ${IS_SERVER}
bootstrap_expect = ${BOOTSTRAP_EXPECT}
}
EOF
# Start Nomad agent
exec /usr/local/bin/nomad agent \
-config="$CONFIG_DIR/server.hcl" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment