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 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
# 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
No tested yet, to be documented.
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
Authorities
tab - Click on
Import...
- Add your
root-ca.crt
- Tick the box
Trust this CA to identify websites.
- Click on
Ok
sudo cp root-ca.crt /usr/local/share/ca-certificates/
sudo update-ca-certificates --fresh
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/root-ca.crt
certutil -addstore -f "ROOT" root-ca.crt
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
# 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
traefik
external 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.yml
below 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'