I try to configure my server with Traefik using Docker containers. I configured Traefik so it works, I got the dashboard page. The thing is I would like to have my own GitLab server. I pulled GitLab docker image and I created a docker-compose file.
Even if GitLab container takes long time to start, it seems to work. I'm able to see the Gitlab backend from Traefik dashboard.
The problem is when I try to go on Gitlab's address, my browser (Firefox and Chrome) tells me that my page is not fully secure. Here's the exact error:
Connection is not secure. Parts of this page are not secure (such as images)
I can't find out why I'm getting this error, my configuration is really basic.
Here's my Traefik.toml config:
defaultEntryPoints = ["http", "https"]
# Web section is for the dashboard interface
[web]
address = ":8080"
[web.auth.basic]
users = ["admin:$apr1$TF1rGQz9$OdtHJ15PT6LGWObE4tXuK0"]
# entryPoints section configures the addresses that Traefik and the proxied containers can listen on
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
# Acme section is for Let's Encrypt configuration
[acme]
email = "email#email.com"
storage = "acme.json"
entryPoint = "https"
onHostRule = true
onDemand = false
[[acme.domains]]
main = "domain.com"
Here's my docker-compose.yml
version: '3.3'
networks:
proxy:
external: true
internal:
external: false
services:
gitlab:
image: gitlab/gitlab-ce
container_name: gitlab
labels:
- traefik.backend=gitlab
- traefik.frontend.rule=Host:git.domain.com
- traefik.docker.network=proxy
- traefik.port=80
networks:
- internal
- proxy
Here's my docker run command for Traefik container:
docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $PWD/traefik.toml:/traefik.toml \
-v $PWD/acme.json:/acme.json \
-e TZ="Europe/Paris" \
-p 80:80 \
-p 443:443 \
-l traefik.frontend.rule=Host:monitor.domain.com \
-l traefik.port=8080 \
--network proxy \
--name traefik \
traefik:1.3.6-alpine --docker --logLevel=DEBUG
As you can see it's a very basic configuration, I don't get why I can't get a fully secure GitLab page. In acme.json file I see my main domain "domain.com" and my sub-domain "git.domain.com". So it should be secure.
What am I missing ? :/
I finally found out why GitLab page was insecure. It's because GitLab use avatar profile picture with insecure path as "htttp://picture_address".
If it can help someone with the same issue :)
Related
My PC is a Windows 10 PRO with Docker Desktop CE Version 2.0.0.3 (31259) (Engine 18.09.2).
I'm building a docker-compose.yml file which runs Traefik, Portainer, GitLab, Jenkins and Registry containers.
Traefik is configured with SSL (self-signed certificate).
I've achieved to run the containers in their domains:
Traefik: https://traefik.localhost
Portainer: https://portainer.localhost
Gitlab: https://gitlab.localhost
Jenkins: https://jenkins.localhost
Registry: https://registry.localhost
When I run these URLs in a browser it returns me certificate error but I access web clients without problems.
If I access the URL https://registry.localhost/v2/_catalog from the browser I can read: {"repositories":[]} This is good. I just started my Registry and it's empty.
I generated the self-signed certificate with:
"C:\Program Files\OpenSSL-Win64\bin\openssl.exe" req -x509 -nodes -days 365 -newkey rsa:2048 -keyout traefik.key -out traefik.crt
I attach the configuration files. I omit part of the docker-compose.yml for short.
docker-compose.yml
version: '3.7'
services:
traefik:
image: traefik
container_name: traefik
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- D:\docker-vols\paas\traefik\traefik.toml:/traefik.toml
- D:\docker-vols\paas\traefik\certs:/certs/
labels:
traefik.enable: true
traefik.frontend.rule: "Host:traefik.localhost"
traefik.port: 8080
# Escapar $ con otro $
traefik.frontend.auth.basic: "root:$$apr1$$3sEZB9aF$$y8ii5P4E8/KAhCiyQoS8I0"
# portainer:
# ...
# gitlab:
# ...
# jenkins:
# ...
registry:
image: registry:2
container_name: registry
volumes:
- D:\docker-vols\paas\registry\registry:/var/lib/registry
labels:
traefik.enable: true
traefik.frontend.rule: "Host:registry.localhost"
traefik.port: 5000
traefik.toml
defaultEntryPoints = ["http", "https"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
certFile = "/certs/traefik.crt"
keyFile = "/certs/traefik.key"
[api]
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "docker.localhost"
watch = true
exposedbydefault = false
I run it: docker-compose up
My problem comes when I want to push an image to my Registry from the host (my Windows PC) to test that it works perfectly. I follow the next steps:
docker pull hello-world
docker tag hello-world registry.localhost/my-hello-world
docker push registry.localhost/my-hello-world
Then it returns
The push refers to repository [registry.localhost/my-hello-world]
Get https://registry.localhost/v2/: dial tcp: lookup registry.localhost on 192.168.65.1:53: no such host
Where's my mistake? Thank you.
SOLUTION:
I forgot to add to /etc/hosts:
127.0.0.1 registry.localhost
I build traefik with cloudflare CDN. I used docker container run command to execute my docker container execute by Drone CI. I have an issue when I successfully built docker container which leads to bad gateway on subdomain.
docker-compose.yml
version: '3'
services:
traefik:
image: traefik:latest
container_name: traefik
restart: always
domainname: ${DOMAINNAME}
networks:
- traefik_proxy
ports:
- "80:80"
- "443:443"
- "8080:8080"
environment:
- CF_API_EMAIL=${CLOUDFLARE_EMAIL}
- CF_API_KEY=${CLOUDFLARE_API_KEY}
labels:
- "traefik.enable=true"
- "traefik.backend=traefik"
- "traefik.frontend.rule=Host:monitor.${DOMAINNAME}"
- "traefik.port=8080"
- "traefik.docker.network=traefik_proxy"
- "traefik.frontend.headers.SSLRedirect=true"
- "traefik.frontend.headers.STSSeconds=315360000"
- "traefik.frontend.headers.browserXSSFilter=true"
- "traefik.frontend.headers.contentTypeNosniff=true"
- "traefik.frontend.headers.forceSTSHeader=true"
- "traefik.frontend.headers.SSLHost=example.com"
- "traefik.frontend.headers.STSIncludeSubdomains=true"
- "traefik.frontend.headers.STSPreload=true"
- "traefik.frontend.headers.frameDeny=true"
- "traefik.frontend.auth.basic.users:${HTTP_USERNAME}:${HTTP_PASSWORD}"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /etc/traefik:/etc/traefik
- /etc/docker/shared:/shared
networks:
traefik_proxy:
external:
name: traefik_proxy
Traefik.toml
nsecureSkipVerify = true
defaultEntryPoints = ["https", "http"]
# WEB interface of Traefik - it will show web page with overview of frontend and backend configurations
[api]
entryPoint = "traefik"
dashboard = true
address = ":8080"
# Force HTTPS
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
# Let's encrypt configuration
[acme]
email = "example#gmail.com" #any email id will work
storage="acme.json"
entryPoint = "https"
acmeLogging=true
onDemand = false #create certificate when container is created
[acme.dnsChallenge]
provider = "cloudflare"
delayBeforeCheck = 300
[[acme.domains]]
main = "example.com"
[[acme.domains]]
main = "*.example.com"
# Connection to docker host system (docker.sock)
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "example.com"
watch = true
# This will hide all docker containers that don't have explicitly
# set label to "enable"
exposedbydefault = false
Command I used to run the docker container execute by Drone:
docker container run -d --name example-development --restart=unless-
stopped --label "traefik.backend=example-development" --label
"traefik.frontend.rule=Host:subdomain.example.com" --label
"traefik.enable=false" --label "traefik.port=6611" --expose 6611
cloud.canister.io:5000/username/repo
My docker container is listening to http://127.0.0.1:6611
Above codes examples lead to Error 504 Gateway Timeout.
Traefik needs to have a common network with the containers it is connecting to. In this case, you need to run containers with --net=traefik_proxy.
If you're container is on multiple networks, you'll also need the label traefik.docker.network=traefik_proxy to tell traefik which of those networks to use.
I'm trying to use traefik with my docker containers for routing.
File structure is:
docker
├── docker-compose.yml
├── shared
│ └── .htpasswd
└── traefik
├── acme
│ └── acme.json
├── rules.toml
└── traefik.toml
Here is traefik.toml:
logLevel = "ERROR"
InsecureSkipVerify = true
defaultEntryPoints = ["https", "http"]
[web]
address = ":8080"
[web.auth.basic]
usersFile = "/shared/.htpasswd"
# Force HTTPS
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[retry]
[file]
watch = true
filename = "/etc/traefik/rules.toml"
[acme]
email = "test#test.com"
storage="/etc/traefik/acme/acme.json"
entryPoint = "https"
acmeLogging=true
onDemand = false #create certificate when container is created
[acme.dnsChallenge]
provider = "digitalocean"
delayBeforeCheck = 0
[[acme.domains]]
main = "test.com"
[[acme.domains]]
main = "*.test.com"
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "test.com"
watch = true
exposedbydefault = false
docker-compose.yml:
version: "3.5"
services:
traefik:
hostname: traefik
image: traefik:latest
container_name: traefik
restart: always
domainname: ${DOMAINNAME}
networks:
- default
- traefik_proxy
ports:
- "80:80"
- "443:443"
#- "8080:8080"
environment:
#- digitalocean=${DO_AUTH_TOKEN}
- DO_AUTH_TOKEN=${DO_AUTH_TOKEN}
labels:
- "traefik.enable=true"
- "traefik.backend=traefik"
- "traefik.frontend.rule=Host:traefik.${DOMAINNAME}"
# - "traefik.frontend.rule=Host:${DOMAINNAME}; PathPrefixStrip: /traefik"
- "traefik.port=8080"
- "traefik.docker.network=traefik_proxy"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ${USERDIR}/docker/traefik:/etc/traefik
- ${USERDIR}/docker/shared:/shared
networks:
traefik_proxy:
external:
name: traefik_proxy
default:
driver: bridge
After running traefik container I'm trying to create another one from the repository:
docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
--label traefik.backend=hello-hapi \
--label traefik.frontend.rule=Host:hello-hapi.test.com \
--label traefik.docker.network=traefik_proxy \
--label traefik.port=80 \
--name hello_hapi \
gitlab.test.com:5555/myuser/hello_hapi:latest
The problem is that I can not access the container through the browser. It prints: hello-hapi.test.com’s server IP address could not be found (ERR_NAME_NOT_RESOLVED).
But the image can be seen in the traefik dashboard and
docker run -it -p 3000:3000 --rm gitlab.test.com:5555/myuser/hello_hapi:latest
runs as expected on test.com:3000
What could be the problem?
Your browser is checking the DNS zone for "test.com" and then in that zone there is no "hello-hapi.test.com" entry.
You need to own the domain in order to add DNS entries for it. If that wasn't the case, I could have my domain as "neekoy.google.com", which Google wouldn't be particularly happy about.
If you want to access it in a browser, you can add a local DNS entry on your computer and point "test.com" to localhost(127.0.0.1). If you don't know how, you can Google "hosts file" for your operating system and add the following line in it:
127.0.0.1 hello-hapi.test.com test.com www.test.com
Hello I have a problem with redirecting HTTP requests to HTTP, when traefik is running in docker and I have mapped the ports.
I am running traefik (v1.5.4 on CentOS as a docker service.
The docker-compose.yml I use to start (docker stack deploy) looks like this
# use docker stack deploy to start a service running traefik
version: '3.6'
services:
proxy:
image: traefik
command: --api --logLevel=DEBUG
networks:
- proxy
ports:
- "70:80"
- "7443:443"
- "7070:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /home/frank/docker/traefik/traefik.toml:/etc/traefik/traefik.toml
The reason for mapping the ports in docker is that on my development system I want to run traefik in parallel to an existing apache.
In my traefik.toml file I try to redirect from Port 80 to 443.
[entryPoints]
# Port 80 (HTTP) is redirected to PORT 443 (HTTPS)
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
Before adding the certificates für HTTPS, I wanted to test the redirection.
It did not work.
I send a request to http:/server.net:70/xxx. And I got a redirection to http:/server.net:443/xxx. What I need or expected was that I would be redirected to http:/server.net:7443/xxx.
Thus my request is not redirected to my app
Is there a way to make this happen?
I think I could in the toml file redirect to port 7443. However, I do not like this solution, since then I will in the traefik configuration use information from the docker configuration. I would prefer to keep them as independent as possible?
I am using traefik as reverse proxy for cryptpad. Traefik is running in a docker container. I used this docs to solve this issue: https://github.com/xwiki-labs/cryptpad/wiki/Docker-(with-Nginx-and-Traefik)#configuring-traefik
That's what I did:
$ mkdir traefik && cd traefik
$ wget https://raw.githubusercontent.com/containous/traefik/master/traefik.sample.toml
$ mv traefik.sample.toml traefik.toml
$ touch acme.json && chmod 600 acme.json
I added this to traefik.toml:
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[retry]
[acme]
email = "me#example.org"
storage = "acme.json"
entryPoint = "https"
onHostRule = true
[acme.httpChallenge]
entryPoint = "http"
Created docker-compose.yml
version: '3'
services:
traefik:
image: traefik
command: --docker
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./traefik/traefik.toml:/traefik.toml
- ./traefik/acme.json:/acme.json
ports:
- 80:80
- 443:443
networks:
- proxy
container_name: traefik
networks:
proxy:
external: true
And created/started traefik with docker-compose up -dll .
Well - for http it works fine so far - but I am not being redirected to https. And if I would, the connection would be reset (https://cryptpad.mydomain.org -> connection refused).
I checked if something is listening for http/https:
tcp LISTEN 0 128 :::http :::*
tcp LISTEN 0 128 :::https :::*
And tried to telnet it:
[root#cryptpad ~]# telnet localhost 443
Trying ::1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
What did I miss?