I am trying out the Katacoda playground for Load Balance Containers using Traefik - https://www.katacoda.com/courses/traefik/deploy-load-balancer:
Here is the exact Docker compose script in the tutorial to start a Traefik node and 2 test containers:
image: traefik
command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
ports:
- "80:80"
- "8080:8080"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /dev/null:/traefik.toml
machine:
image: katacoda/docker-http-server
labels:
- "traefik.backend=machine-echo"
- "traefik.frontend.rule=Host:machine-echo.example.com"
echo:
image: katacoda/docker-http-server:v2
labels:
- "traefik.backend=echo"
- "traefik.frontend.rule=Host:echo-echo.example.com"
I run Docker-Compose command, as given in tutorial:
$ docker-compose up -d
Creating tutorial_traefik_1 ... done
Creating tutorial_echo_1 ... done
Creating tutorial_machine_1 ... done
However when I check the container list, I can see only 2 containers are created. The Traefik container is not created:
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
35e87a3ff6ed katacoda/docker-http-server "/app" 11 seconds ago Up 9 seconds 80/tcp tutorial_machine_1
a455019d16be katacoda/docker-http-server:v2 "/app" 11 seconds ago Up 9 seconds 80/tcp tutorial_echo_1
The next step fails too. This may be because the Traefik container is not running:
$ curl -H Host:machine-echo.example.com http://host01
curl: (7) Failed to connect to host01 port 80: Connection refused
Can anyone replicate this tutorial and please let me know the cause and fix for this error?
Just run on this today, you must hardcode traefik version to 1.7.32
traefik:
image: traefik:1.7.32
command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
ports:
- "80:80"
- "8080:8080"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /dev/null:/traefik.toml
machine:
image: katacoda/docker-http-server
labels:
- "traefik.backend=machine-echo"
- "traefik.frontend.rule=Host:machine-echo.example.com"
echo:
image: katacoda/docker-http-server:v2
labels:
- "traefik.backend=echo"
- "traefik.frontend.rule=Host:echo-echo.example.com"
Related
I am trying to make combination of docker + consul + traefik from last several days and it doesn't seem to be working. I am at a point where I just don't know what I am missing in my configuration.
My docker host IP address is: 192.168.30.12
I created a bridge network called consulwhich has a subnet of 172.28.0.5/16
Here is my docker compose for consul (for simplicity, I am running just one consul server so that I can debug an issue)
services:
consul-server:
container_name: consul-server-bootstrap
image: consul:latest
networks:
- consul
ports:
- 8400:8400
- 8500:8500
- 53:8600
- 53:8600/udp
command: agent -server -bootstrap -ui -node=consul-server -client=0.0.0.0 -advertise=192.168.30.12 -recursor=8.8.8.8
restart: unless-stopped
I am using registrator to register service to the consul. Here is docker compose for that service:
registrator:
image: gliderlabs/registrator:latest
volumes:
- /var/run/docker.sock:/tmp/docker.sock
container_name: consul-registrator
restart: unless-stopped
command: consul://consul-server-bootstrap:8500
networks:
- consul
Here is my traefik docker compose section
reverse-proxy:
container_name: traefik
image: traefik:v2.9
networks:
- consul
command: --api.insecure=true --providers.consulcatalog=true --providers.consulcatalog.prefix=traefik --providers.consulcatalog.endpoint.address=http://192.168.30.12:8500
ports:
- "80:80"
- "8080:8080"
Here is whoami container that I am registering with consul
whoami:
# A container that exposes an API to show its IP address
image: traefik/whoami
networks:
- consul
restart: unless-stopped
environment:
- SERVICE_TAGS=whoami
- SERVICE_NAME=whoami
- SERVICE_80_ID=whoami
ports:
- "80"
labels:
- traefik.enable=true
- traefik.backend=whoami
- traefik.port=80
- traefik.default.protocol=http
- traefik.http.routers.whoami.rule=Host(`whoami`)
When I visit http://192.168.30.12:8500, I see that whoami is registered with consul as seen below:
I see whoami on traefik dashboard as well when I visit http://192.168.30.12:8080
I also run dig command dig #127.0.0.1 whoami.service.consul on my docker host and that also can discover the service just fine as seen below:
I made a host entry on my other computer as seen below
192.168.30.12 whoami
When I try to visit http://whoami in browser, I get "Bad Gateway" error.
I want to register new containers to consul using registrator and than add it to the traefik load balancer using service tags and then consume those service from outside of my docker host.
Can someone please point me where I am making mistake. I have spent several days on it to make it work.
I have my docker-compose.yml with this code i have added 2 services. This successfully build with docker-compose up -d --build
version: "2"
services:
expo:
build:
context: ./dev
dockerfile: Dockerfile
container_name: sis-expo
working_dir: /home/node/app
volumes:
- .:/home/node/app
environment:
- NODE_ENV=development
#- EXPO_DEVTOOLS_LISTEN_ADDRESS=0.0.0.0
- ADB_IP=192.168.1.1
- REACT_NATIVE_PACKAGER_HOSTNAME=192.168.1.33
expose:
- "19000"
- "19001"
- "19002"
ports:
- 19000:19000
- 19001:19001
- 19002:19002
tty: true
firebase:
build:
context: ./dev
dockerfile: firebase.dockerfile
container_name: sis-expo-firebase
ports:
- 4000:4000 # Emulator Suite UI
- 5000:5000 # Firebase Hosting
- 5001:5001 # Clound Functions
- 9000:9000 # Realtime Database
- 8080:8080 # Cloud Firestore
- 8085:8085 # Cloud Pub/Sub
- 9005:9005
command: "echo this is a test"
then run docker-compose up -d to start container then i check with docker ps but the container isn't there then i tried to do docker ps -a it show container exited.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
511c3cf9163c sis-mobile_firebase "docker-entrypoint.s…" About a minute ago Exited (0) 11 seconds ago sis-expo-firebase
And its logs can be viewed with docker logs <id>.
this is a test
Please let me know if you need further information. Not sure if this is enough to truly solve my problem. thanks a lot.
I'm following some tutorial link_to_tutorial about traefik 2.0 and docker, and I have docker-compose file which starts up two containers: traefik and my-app. The problem is when containers up and running, I am not able to browse to localhost:8082, as suggested by configuration, I always get "unable to connect" in browser.
docker-compose.yml :
version: "3.3"
services:
traefik:
image: "traefik:v2.0.1"
command:
- --entrypoints.web.address=:80
- --providers.docker
- --api.insecure
ports:
- "80:80"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
my-app:
image: containous/whoami:v1.3.0
command:
# It tells whoami to start listening on 8082 instead of 80
- --port=8082
labels:
- "traefik.http.routers.my-app.rule=Host(`whoami.docker.localhost`)"
- "traefik.http.services.my-app.loadbalancer.server.port=8082"
However I am able to get localhost:8080 and traefik UI works well. As I understand all requests to "traefik" container normally should be redirected to "my-app":8082 container but it somehow fails. Help heeded.Thanks.
"traefik.http.routers.my-app.rule=Host(localhost,127.0.0.1)"
I want to bind my docker binaries and docker.sock to my docker jenkins container so that i will be able to use docker inside jenkins. This is my docker-compose.yml
version: "2"
services:
traefik:
image: traefik
restart: always
container_name: "${PROJECT_NAME}_traefik"
command: --api --docker
ports:
- '80:80'
- '443:443'
volumes:
- ./traefik.toml:/traefik.toml
- ./acme.json:/acme.json
labels:
- "traefik.frontend.rule=Host:${PROJECT_BASE_URL}"
jenkins:
#image: jenkins/jenkins
build: .
container_name: "${PROJECT_NAME}_jenkins"
environment:
- "JAVA_OPTS=-Dmail.smtp.starttls.enable=true"
ports:
- '50000:50000'
volumes:
- ./jenkins_home:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
labels:
- "traefik.frontend.rule=Host:${PROJECT_BASE_URL}"
Is there something I missed? I am not using sudo when running docker-compose start.
You need to make the jenkins container privileged to access a device. By default this is turned off, probably for security.
See https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities for more details, it even gives the example of running the docker daemon.
In your docker compose file add privileged: true to your jenkins service
I have below YAML file :
seleniumhub:
image: selenium/hub
ports:
- 4444:4444
firefoxnode:
image: selenium/node-firefox-debug
ports:
- 4577
links:
- seleniumhub:hub
expose:
- "5900"
chromenode:
image : selenium/node-chrome-debug
ports:
- 4578
links:
- seleniumhub:hub
expose:
- "5900"
docker ps:
time="2017-04-01T17:57:44+03:00" level=info msg="Unable to use system certificate pool: crypto/x509: system root pool is not available on Windows"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9d2ccb193b54 selenium/node-firefox-debug "/opt/bin/entry_po..." 6 seconds ago Up 5 seconds 5900/tcp, 0.0.0.0:32785->4577/tcp dockercompose_firefoxnode_1
4be6223fe043 selenium/node-chrome-debug "/opt/bin/entry_po..." 6 seconds ago Up 5 seconds 5900/tcp, 0.0.0.0:32784->4578/tcp dockercompose_chromenode_1
7d95d3e73016 selenium/hub "/opt/bin/entry_po..." 7 seconds ago Up 6 seconds 0.0.0.0:4444->4444/tcp dockercompose_seleniumhub_1
But whenever I run below command in Docker quick start terminal:
docker port 9d2ccb193b54 5900
I got below:
Error: No public port '5900/tcp' published for 9d2ccb193b54
and I'm not able to connect to the node machines through VNC
for firefoxnode try this configuration:
image: selenium/node-firefox-debug
ports:
- 4577
- 5900
links:
- seleniumhub:hub
expose:
- "5900"
expose does not publish port to the host machine and only accessible to linked services. It works for inter-container communication. ports will expose that port to host machine.
For exposing ports the syntax is:
ports:
- "host:container"
In your case:
image: selenium/node-firefox-debug
ports:
- 4577
- "5900:5900"
links:
- seleniumhub:hub