Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dnsmasq as an optional container #8

Open
wants to merge 1 commit into
base: legacy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,49 @@ chmod u+x ./scripts/generate-certificates.sh
```
You need to add the generated certificate `certificates/docker.rootCA.crt` to your browser authorities and trust related websites.

### Setup local DNS

To be able to resolve all DNS lookup to *.pontsun.test (or other configured domains), we need a local dns server.
There's 2 options to do that, either in the provided docker container. Or in a locally installed dns server like dnsmasq.


#### 1) Use the included dns server container

Do use the included dnsmasq container, start pontsun with

```bash
cd containers
docker-compose -f docker-compose.yml -f docker-compose.dns.yml up -d
```

You can also add the following to your `containers/.env` file instead

```
COMPOSE_FILE=docker-compose.yml:docker-compose.dns.yml
```

#### or 3) Use a locally installed dns server

See

- [Docker installation for Mac](docs/docker-installation-for-mac.md)
- [Docker installation for Ubuntu](docs/docker-installation-for-ubuntu.md)

for detilas

#### Add domain to your dns config

After you have set the dns server up, do:

```bash
. containers/.env
./scripts/pontsun add-host $PROJECT_DOMAIN
```

do add your default domain (by default pontsun.test) to the dns server.

### Start pontsun with traefik and portainer

Start Traefik and Portainer
```bash
cd containers
Expand Down
7 changes: 7 additions & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

cd $DIR
docker build -t liip/pontsun-dnsmasq:latest dnsmasq
8 changes: 8 additions & 0 deletions build/dnsmasq/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM alpine:edge
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this should not be part of this repo but available as a global image on the Liip docker registry.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where would you put the Dockerfile then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in a dedicated repo so it can be managed in parallel of Pontsun. But this can be later of course.


RUN apk --no-cache add dnsmasq

ADD dnsmasq.conf /etc/

EXPOSE 53 53/udp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably avoid creating an image with a root user just in case.

ENTRYPOINT ["dnsmasq", "-d"]
11 changes: 11 additions & 0 deletions build/dnsmasq/dnsmasq.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#dnsmasq config, for a complete example, see:
# http://oss.segetech.com/intra/srv/dnsmasq.conf
#log all dns queries
log-queries
#dont use hosts nameservers
no-resolv
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider no-hosts also ?

#use cloudflare as default nameservers, prefer 1^4
server=1.0.0.1
server=1.1.1.1
strict-order
conf-dir=/etc/dnsmasq.d/,*.conf
15 changes: 15 additions & 0 deletions containers/docker-compose.dns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.5'
services:
dns:
image: liip/pontsun-dnsmasq:latest
container_name: pontsun_dns
restart: always
volumes:
- "$PONTSUN_DIR_ETC/dnsmasq.d/:/etc/dnsmasq.d/"
ports:
- 53:53/udp
networks:
- pontsun
logging:
options:
max-size: 20m
25 changes: 16 additions & 9 deletions docs/docker-installation-for-mac.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,37 @@ gem install docker-sync

## Dnsmasq

Dnsmasq will automatically forward any **\*.docker.lo** domain to our
Dnsmasq will automatically forward any **\*.pontsun.test** domain to our
local docker infrastructure.

```
brew install dnsmasq
```

```
mkdir -pv $(brew --prefix)/etc/
echo 'address=/docker.lo/127.0.0.1' > $(brew --prefix)/etc/dnsmasq.conf
echo 'strict-order' >> $(brew --prefix)/etc/dnsmasq.conf
mkdir -pv $(brew --prefix)/etc/dnsmasq.d/
echo 'strict-order' > $(brew --prefix)/etc/dnsmasq.conf
echo 'conf-dir='$(brew --prefix)'/etc/dnsmasq.d/,*.conf' >> $(brew --prefix)/etc/dnsmasq.conf
```

and then
```
sudo cp -v $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
```


./scripts/add-host.sh pontsun.test
```
or if you prefer to do it by hand
```
echo address=/$1/127.0.0.1 > $(brew --prefix)/dnsmasq.d/pontsun.test.conf
echo 'strict-order' >> $(brew --prefix)/dnsmasq.d/pontsun.test.conf
sudo mkdir -v /etc/resolver
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/docker.lo'
```

and in the end
```
sudo cp -v $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
```

## Pontsun

Pontsun provides the base setup for Docker environments.
Expand Down
13 changes: 11 additions & 2 deletions docs/docker-installation-for-ubuntu.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ sudo apt-get install dnsmasq

```
mkdir -pv /etc/dnsmasq.d/
echo 'address=/docker.lo/127.0.0.1' | sudo tee /etc/dnsmasq.d/docker
echo 'strict-order' | sudo tee --append /etc/dnsmasq.d/docker
```
and then
```
./scripts/add-host pontsun.test
```

or if you prefer to do it by hand
```
echo 'address=/pontsun.test/127.0.0.1' | sudo tee /etc/dnsmasq.d/pontsun.test.conf
echo 'strict-order' | sudo tee --append /etc/dnsmasq.d/pontsun.test.conf
```

## Pontsun

Pontsun provides the base setup for Docker environments.
Expand Down
51 changes: 51 additions & 0 deletions scripts/add-host.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this part should added to pontsun-cli rather than here ?

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PONTSUN_DNS=$(docker inspect -f '{{.State.Running}}' pontsun_dns 2> /dev/null || echo 'false')

if [[ $PONTSUN_DNS == 'true' ]]; then
DOCKER_COMPOSE="docker-compose -f docker-compose.yml -f docker-compose.dns.yml"
cd $DIR/../containers/
if $DOCKER_COMPOSE exec dns ash -c "if [[ -f /etc/dnsmasq.d/$1.conf ]]; then exit 1; fi; echo address=/$1/127.0.0.1 > /etc/dnsmasq.d/$1.conf"
then
$DOCKER_COMPOSE restart dns
fi
else
# no DNS container.
# write it to system dnsmasq

if [[ "$OSTYPE" == "darwin"* ]]; then
ETC_PREFIX=$(brew --prefix)'/etc'
else
ETC_PREFIX='/etc'
fi

if [[ ! -d $ETC_PREFIX/dnsmasq.d/ ]]; then
RED='\033[0;31m'
NC='\033[0m' # No Color

printf "${RED}pontsun_dns is not running and can't find $ETC_PREFIX/dnsmasq.d${NC}\n"
printf "Please install dnsmasq locally or start potsun_dns"
exit 1
fi

if [[ ! -f $ETC_PREFIX/dnsmasq.d/$1.conf ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
echo address=/$1/127.0.0.1 > $ETC_PREFIX/dnsmasq.d/$1.conf
echo 'strict-order' >> $ETC_PREFIX/dnsmasq.d/$1.conf
else
echo address=/$1/127.0.0.1 | sudo tee $ETC_PREFIX/dnsmasq.d/$1.conf
echo 'strict-order' | sudo tee --append $ETC_PREFIX/dnsmasq.d/$1.conf
fi
echo "dnsmasq entry updated, you may restart it to take effect."
else
echo "No dnsmasq changes done, $ETC_PREFIX/dnsmasq.d/$1.conf already exists."
fi
fi

if [[ "$OSTYPE" == "darwin"* ]] && [[ ! -f /etc/resolver/$1 ]]; then
echo "Adding to /etc/resolver/$1"
sudo mkdir -vp /etc/resolver
sudo bash -c "echo 'nameserver 127.0.0.1' > /etc/resolver/$1"
fi