From 4a20c0f5f1cc8d3f0598ca57a5b360690aa36dd2 Mon Sep 17 00:00:00 2001 From: David Siaw Date: Tue, 16 Jul 2024 16:41:39 +0900 Subject: [PATCH] fix dns in docker mode --- README.md | 4 ++-- lib/kaiser/cli.rb | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 69ad582b..51f3a5f8 100644 --- a/README.md +++ b/README.md @@ -38,14 +38,14 @@ docker build -t degica/kaiser . And then add the following line to your `.bashrc` or `.bash_profile` ``` -alias kaiser='docker run --pull=always --rm -ti -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kaiser:/root/.kaiser -v `pwd`:`pwd` -e CONTEXT_DIR="`pwd`" degicadev/kaiser' +alias kaiser='docker run --pull=always --rm -ti -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kaiser:/root/.kaiser -v `pwd`:`pwd` -e _KAISER_USER_HOME=$HOME -e _KAISER_POS=docker -e CONTEXT_DIR="`pwd`" degicadev/kaiser' ``` Or if you use fish ``` function kaiser - docker run --pull=always --rm -ti -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kaiser:/root/.kaiser -v (pwd):(pwd) -e CONTEXT_DIR=(pwd) degicadev/kaiser $argv + docker run --pull=always --rm -ti -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kaiser:/root/.kaiser -v (pwd):(pwd) -e _KAISER_USER_HOME=$HOME -e _KAISER_POS=docker -e CONTEXT_DIR=(pwd) degicadev/kaiser $argv end ``` diff --git a/lib/kaiser/cli.rb b/lib/kaiser/cli.rb index 2082a54f..801c8c57 100644 --- a/lib/kaiser/cli.rb +++ b/lib/kaiser/cli.rb @@ -571,8 +571,14 @@ def ensure_setup jwilder/nginx-proxy" ) - dnsconffile = "#{ENV['HOME']}/.kaiser/dnsconf" - File.write(dnsconffile, <<~HOSTS) + homedir_loc = ENV['HOME'] + if ENV['_KAISER_POS'] == 'docker' + homedir_loc = ENV['_KAISER_USER_HOME'] + end + + innerdnsconffile = "#{ENV['HOME']}/.kaiser/dnsconf" + outerdnsconffile = "#{homedir_loc}/.kaiser/dnsconf" + File.write(innerdnsconffile, <<~HOSTS) log-queries no-resolv server=8.8.8.8 @@ -585,7 +591,7 @@ def ensure_setup "docker run -d --name #{Config.config[:shared_names][:dns]} --network #{Config.config[:networkname]} - -v #{dnsconffile}:/etc/dnsmasq.conf:ro + -v #{outerdnsconffile}:/etc/dnsmasq.conf:ro degica/dnsmasq " )