[#4] 构建bind9镜像
This commit is contained in:
44
src/bind/build/Dockerfile
Normal file
44
src/bind/build/Dockerfile
Normal file
@@ -0,0 +1,44 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
# Set timezone and avoid interactive prompts
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
||||
# Update package list and install required packages
|
||||
RUN apt-get update && \
|
||||
apt-get install -y \
|
||||
bind9 \
|
||||
bind9utils \
|
||||
bind9-doc \
|
||||
supervisor \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create supervisor configuration directory
|
||||
RUN mkdir -p /etc/supervisor/conf.d
|
||||
|
||||
# Copy supervisor configuration
|
||||
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
|
||||
# Copy BIND9 configuration files
|
||||
COPY named.conf.local /etc/bind/named.conf.local
|
||||
COPY db.argus.com /etc/bind/db.argus.com
|
||||
|
||||
# Copy startup and reload scripts
|
||||
COPY startup.sh /usr/local/bin/startup.sh
|
||||
COPY reload-bind9.sh /usr/local/bin/reload-bind9.sh
|
||||
|
||||
# Make scripts executable
|
||||
RUN chmod +x /usr/local/bin/startup.sh /usr/local/bin/reload-bind9.sh
|
||||
|
||||
# Set proper ownership for BIND9 files
|
||||
RUN chown bind:bind /etc/bind/named.conf.local /etc/bind/db.argus.com
|
||||
|
||||
# Expose DNS port
|
||||
EXPOSE 53/tcp 53/udp
|
||||
|
||||
# Use root user as requested
|
||||
USER root
|
||||
|
||||
# Start with startup script
|
||||
CMD ["/usr/local/bin/startup.sh"]
|
||||
16
src/bind/build/db.argus.com
Normal file
16
src/bind/build/db.argus.com
Normal file
@@ -0,0 +1,16 @@
|
||||
$TTL 604800
|
||||
@ IN SOA ns1.argus.com. admin.argus.com. (
|
||||
2 ; Serial
|
||||
604800 ; Refresh
|
||||
86400 ; Retry
|
||||
2419200 ; Expire
|
||||
604800 ) ; Negative Cache TTL
|
||||
|
||||
; 定义 DNS 服务器
|
||||
@ IN NS ns1.argus.com.
|
||||
|
||||
; 定义 ns1 主机
|
||||
ns1 IN A 127.0.0.1
|
||||
|
||||
; 定义 web 指向 12.4.5.6
|
||||
web IN A 12.4.5.6
|
||||
4
src/bind/build/named.conf.local
Normal file
4
src/bind/build/named.conf.local
Normal file
@@ -0,0 +1,4 @@
|
||||
zone "argus.com" {
|
||||
type master;
|
||||
file "/etc/bind/db.argus.com";
|
||||
};
|
||||
16
src/bind/build/private/argus/bind/db.argus.com
Normal file
16
src/bind/build/private/argus/bind/db.argus.com
Normal file
@@ -0,0 +1,16 @@
|
||||
$TTL 604800
|
||||
@ IN SOA ns1.argus.com. admin.argus.com. (
|
||||
2 ; Serial
|
||||
604800 ; Refresh
|
||||
86400 ; Retry
|
||||
2419200 ; Expire
|
||||
604800 ) ; Negative Cache TTL
|
||||
|
||||
; 定义 DNS 服务器
|
||||
@ IN NS ns1.argus.com.
|
||||
|
||||
; 定义 ns1 主机
|
||||
ns1 IN A 127.0.0.1
|
||||
|
||||
; 定义 web 指向 12.4.5.6
|
||||
web IN A 22.4.5.6
|
||||
4
src/bind/build/private/argus/bind/named.conf.local
Normal file
4
src/bind/build/private/argus/bind/named.conf.local
Normal file
@@ -0,0 +1,4 @@
|
||||
zone "argus.com" {
|
||||
type master;
|
||||
file "/etc/bind/db.argus.com";
|
||||
};
|
||||
27
src/bind/build/reload-bind9.sh
Normal file
27
src/bind/build/reload-bind9.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Reloading BIND9 configuration..."
|
||||
|
||||
# Check if configuration files are valid
|
||||
echo "Checking named.conf.local syntax..."
|
||||
if ! named-checkconf /etc/bind/named.conf.local; then
|
||||
echo "ERROR: named.conf.local has syntax errors!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Checking zone file syntax..."
|
||||
if ! named-checkzone argus.com /etc/bind/db.argus.com; then
|
||||
echo "ERROR: db.argus.com has syntax errors!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Reload BIND9 via supervisor
|
||||
echo "Reloading BIND9 service..."
|
||||
supervisorctl restart bind9
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "BIND9 reloaded successfully!"
|
||||
else
|
||||
echo "ERROR: Failed to reload BIND9!"
|
||||
exit 1
|
||||
fi
|
||||
29
src/bind/build/startup.sh
Normal file
29
src/bind/build/startup.sh
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Set /private permissions to 777 as requested
|
||||
chmod 777 /private 2>/dev/null || true
|
||||
|
||||
# Create persistent directory for BIND9 configs
|
||||
mkdir -p /private/argus/bind
|
||||
|
||||
# Copy configuration files to persistent storage if they don't exist
|
||||
if [ ! -f /private/argus/bind/named.conf.local ]; then
|
||||
cp /etc/bind/named.conf.local /private/argus/bind/named.conf.local
|
||||
fi
|
||||
|
||||
if [ ! -f /private/argus/bind/db.argus.com ]; then
|
||||
cp /etc/bind/db.argus.com /private/argus/bind/db.argus.com
|
||||
fi
|
||||
|
||||
# Create symlinks to use persistent configs
|
||||
ln -sf /private/argus/bind/named.conf.local /etc/bind/named.conf.local
|
||||
ln -sf /private/argus/bind/db.argus.com /etc/bind/db.argus.com
|
||||
|
||||
# Set proper ownership
|
||||
chown bind:bind /private/argus/bind/named.conf.local /private/argus/bind/db.argus.com
|
||||
|
||||
# Create supervisor log directory
|
||||
mkdir -p /var/log/supervisor
|
||||
|
||||
# Start supervisor
|
||||
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
|
||||
24
src/bind/build/supervisord.conf
Normal file
24
src/bind/build/supervisord.conf
Normal file
@@ -0,0 +1,24 @@
|
||||
[unix_http_server]
|
||||
file=/var/run/supervisor.sock
|
||||
chmod=0700
|
||||
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
user=root
|
||||
logfile=/var/log/supervisor/supervisord.log
|
||||
pidfile=/var/run/supervisord.pid
|
||||
|
||||
[rpcinterface:supervisor]
|
||||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
||||
|
||||
[supervisorctl]
|
||||
serverurl=unix:///var/run/supervisor.sock
|
||||
|
||||
[program:bind9]
|
||||
command=/usr/sbin/named -g -c /etc/bind/named.conf -u bind
|
||||
user=bind
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stderr_logfile=/var/log/supervisor/bind9.err.log
|
||||
stdout_logfile=/var/log/supervisor/bind9.out.log
|
||||
priority=10
|
||||
Reference in New Issue
Block a user