docker-hostmanager
docker-hostmanager copied to clipboard
Access your Docker containers using domain names either with HTTP or HTTPS
Docker HostManager
Access your Docker containers using domain names either with HTTP or HTTPS.
The Docker HostManager update your hosts file and generate TLS certificates
when a container gets created with just a couple of labels.
Run
Linux
# Run the docker manager
docker run --detach -t --name docker-hostmanager \
--restart always \
--volume docker-hostmanager-data:/data:rw \
--volume /etc/hosts:/host/etc/hosts:rw \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
gcanal/docker-hostmanager:latest
Mac
# Make your /etc/hosts/ writable
sudo chmod 777 /etc/hosts
# Run the docker manager
docker run --detach -t --name docker-hostmanager \
--restart always \
--volume docker-hostmanager-data:/data:rw \
--volume /private/etc/hosts:/host/etc/hosts:rw \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
gcanal/docker-hostmanager:latest
Windows
No tested yet, to be documented.
Install the root certificate
In order to access your domains using HTTPS, you will need to add the Root Certificate generated by DockerHostManager
in your browsers and in your trusted root certification authorities.
# Copy the certificate from a docker volume anywhere on your host machine
docker cp docker-hostmanager:/data/root-ca.crt .
Note: if you are using Firefox, you will need to add your certificate using the following method :
- Open
Preferences - On the top right corner, search:
certificates - Click on
View Certificates... - Click on the
Authoritiestab - Click on
Import... - Add your
root-ca.crt - Tick the box
Trust this CA to identify websites. - Click on
Ok
Linux (Ubuntu, Debian)
sudo cp root-ca.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates --fresh
Mac
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/root-ca.crt
Windows
certutil -addstore -f "ROOT" root-ca.crt
Usage example
Using the Docker CLI
docker run --rm -t \
--label 'traefik.enable=true' \
--label 'traefik.port=80' \
--label 'traefik.frontend.rule=Host: nginx.docker' \
nginx:alpine
Head to http://nginx.docker or https://nginx.docker
Using Docker Compose
# docker-compose.yml
version: '3'
services:
foo:
image: 'containous/whoami'
networks: ['traefik']
labels:
- 'traefik.enable=true'
- 'traefik.port=80'
- 'traefik.frontend.rule=Host: dev.demo.fr'
networks:
traefik:
external: true
Head to http://dev.demo.fr or https://dev.demo.fr
Note: Declaring the
traefikexternal network is not mandatory.
Without it, Docker HostManager will attach the traefik network to each containers having traefik labels.
Doing so, it will restart the Traefik instance. Thedocker-composer.ymlbelow is perflectly fine as well:
# docker-compose.yml
version: '3'
services:
foo:
image: 'containous/whoami'
labels:
- 'traefik.enable=true'
- 'traefik.port=80'
- 'traefik.frontend.rule=Host: dev.demo.fr'