Skip to content

Access your Docker containers using domain names either with HTTP or HTTPS

License

Notifications You must be signed in to change notification settings

guillemcanal/docker-hostmanager

Repository files navigation

Docker HostManager

Build Status codecov quality smells

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 :

  1. Open Preferences
  2. On the top right corner, search: certificates
  3. Click on View Certificates...
  4. Click on the Authorities tab
  5. Click on Import...
  6. Add your root-ca.crt
  7. Tick the box Trust this CA to identify websites.
  8. 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 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. The docker-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'

About

Access your Docker containers using domain names either with HTTP or HTTPS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages