최신글 참고 : https://positively.tistory.com/20
wireguard gui(wg-easy*) 설정 후 서버 자체 dns활용을 하지 못하는 현상 발생하여 linuxserver/wireguard 이미지를 참고하여 CoreDNS** 적용
* wireguard gui 코드 사이트 : https://github.com/WeeJeWel/wg-easy
* CoreDns 코드 사이트 https://github.com/coredns/
□ docker-compose 내 entrypoint 와 command 조합으로 자동 실행
entrypoint : 환경적 변화가 적은 수행
command : 환경적 변화에 따라 수행
entrypoint: ["docker-entrypoint.sh"]
command:
sh -c "/usr/bin/dumb-init node server.js &&
cd /app &&
/usr/bin/wget https://github.com/coredns/coredns/releases/download/v1.9.3/coredns_1.9.3_linux_amd64.tgz &&
/bin/tar -zxvf coredns_1.9.3_linux_amd64.tgz &&
echo -e '{\n loop\n forward /etc/resolv.conf \n }' >>Corefile &&
./app/coredns -dns.port=53"
더보기
1. CoreDNS github 사이트를 통해 바이너리 다운, 압축 해제
wget <다운로드 소스 링크>
unzip <다운로드 바이너리> # zip 파일일 경우
tar -zxvf <다운로드 바이너리> # tgz 파일일 경우
2. /app/coredns, 동일위치에 Corefile 파일 생성
sudo touch Corefile
Corefile 내용
. {
loop
forward . /etc/resolv.conf
}
▼ 처음 CoreDNS 적용을 위해 Dokcer container가 올라오면 자동으로 서비스가 작동 되게 구현하려 하였으나,
wg-easy 이미지에서는 init.d 작동이 되지 않아 대안을 모색
대안
wg-easy 컨테이너의 시작 엔트리포인트 바이너리 내에 /usr/local/bin/docker-entrypoint.sh
#!/bin/sh
set -e
# Run command with node if the first argument contains a "-" or is not a system command. The last
# part inside the "{}" is a workaround for the following bug in ash/dash:
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=874264
if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ] || { [ -f "${1}" ] && ! [ -x "${1}" ]; }; then
set -- node "$@"
fi
exec nohup /app/coredns -dns.port=53 >/dev/null 2>&1 & # 구문추가
exec "$@"
" exec nohup /app/coredns -dns.port=53 >/dev/null 2>&1 " 구문 추가
3. init.d 혹은 service 생성이 가능하다면 아래 스크립트 참고
도커 내 서비스 생성 /etc/init.d/coredns
#!/bin/bash
### BEGIN INIT INFO
# Provides:coredns
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop coredns
### END INIT INFO
PROG_PID=${PROG_PID}
PROG_TAG=coredns
PROG_EXE=/app/${PROG_TAG}
set -e
test -x ${PROG_EXE} || exit 0
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin:/app"
case "$1" in
start)
if netstat -apn | grep ":53 "; then
echo "Another service is using port 53, disabling CoreDNS"
sleep infinity
else
exec /app/coredns -dns.port=53
echo "Starting DDNS client" "${PROG_TAG}"
fi
${PROG_EXE}
;;
stop)
echo "Stopping DDNS client" "${PROG_TAG}"
killall `basename ${PROG_EXE}`
;;
restart)
$0 stop
sleep 1
$0 start
;;
status)
ps -ef|grep ${PROG_EXE} | grep -v grep | grep ${PROG_EXE}
;;
*)
echo "Usage: $0 {start|stop|restart|status}" || true
exit 1
esac
exit 0
'IT' 카테고리의 다른 글
| exiftool 사용법 (구글포토) (0) | 2022.07.13 |
|---|---|
| GeoIP for Ubuntu (0) | 2022.07.13 |
| linux bandwith limit (0) | 2022.07.13 |
| WSL DOCKER PS 오류 발생 해결 (0) | 2022.07.13 |
| SSH 터널링 (0) | 2022.07.13 |