Running tensorboard behind traefik - tensorboard

I am trying to add a tensorboard container to an existing microservice structure running behind traefik. Unfortunately, the traefik version is 1.5 so a lot of recent articles are not helpful.
Since there is a default service on www.my-server.com/, I am trying to have traefik redirect to the tensorboard service from www.my-server.com/tensorboard/. Here is my docker-compose (the part relevant for tensorboard)
tensorboard:
build: "./docker/build/images/tensorflow"
container_name: tensorboard
command: tensorboard --logdir=runs --port=8888 --host=0.0.0.0
labels:
- log.level=debug
- traefik.enable=true
- traefik.frontend.rule=Host:www.my-server.com;PathPrefix:/tensorboard/
volumes:
- ./machine_learning:/opt/src
ipc: host
When I visit www.my-server.com/tensorboard/ I get "Not Found". If I remove the host argument from the command I get "Bad Gateway". I don't understand what either of these mean but I think one of them is being able to reach the service but the service is getting the request with the prefix tensorboard and is complaining.
How do I make this work?

Turns out that the following command will solve this problem
tensorboard --logdir mylogdir --bind_all --path_prefix=/tensorboard

Related

Django WebSocket not working inside a container but works outside of it

I am trying to do a connection to a websocket from a html page in django. This works when i run it outside a container but it stops working inside of it .
My server inside my docker compose.
server:
stdin_open: true # docker run -i
tty: true # docker run -t
build:
dockerfile: server.Dockerfile
context: ./
volumes:
- /home/$USER/.ssh:/root/.ssh
ports:
- '8000:8000'
networks:
drone_net:
ipv4_address: 10.10.10.2
the url I use in my html page
let url = `ws://localhost:8000/ws/socket-server/`
The error i get: WebSocket connection to 'ws://localhost:8000/ws/socket-server/' failed:
This is my routing for the websocket :
websocket_urlpatterns=[
re_path(r'ws/socket-server/',consumers.ChatConsumer.as_asgi())
]
I first thought it was localhost not working but my http request works in the containe as well.
I tried to change the value of the url with different ones.
I thought it was localhost that wasnt working properly but i also use local host for http request and they were fine in the container.
I was expecting it to work.
I found the solution. Weirldy it was a problem of package channel Version. In the docker file, I took the most recent version of channels: 4.0.0. While my local computer was using channels.version 3.0.5. When I downgraded the version, it solved my problem.

Docker-compose - Cannot connect to Postgres

It looks like a common issue: can't connect to Postgres from a Django app in Docker Compose.
Actually, I tried several solution from the web, but probably I'm missing something I cannot see.
The error I got is:
django.db.utils.OperationalError: could not translate host name "db" to address: Try again
Where the "db" should be the name of the docker-compose service and which must setup in the .env.
My docker-compose.yml:
version: '3.3'
services:
web:
build: .
container_name: drf_app
volumes:
- ./src:/drf
links:
- db:db
ports:
- 9090:8080
env_file:
- /.env
depends_on:
- db
db:
image: postgres:13-alpine
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
- POSTGRES_USER=myuser
- POSTGRES_PASSWORD=mypass
- POSTGRES_DB=mydb
volumes:
- postgres_data:/var/lib/postgresql/data/
ports:
- 5432:5432
volumes:
postgres_data:
My .env:
SQL_ENGINE=django.db.backends.postgresql
SQL_DATABASE=mydb
SQL_USER=myuser
SQL_PASSWORD=mypass
SQL_HOST=db #this one should match the service name
SQL_PORT=5432
As far as I know, web and db should automatically see each other in the same network, but this doesn't happens.
Inspecting the ip address with ifconfig on each container: django app has 172.17.0.2 and the db 172.19.0.2. They are not able to ping each other.
The result of docker ps command:
400879d47887 postgres:13-alpine "docker-entrypoint.s…" 38 minutes ago Up 38 minutes 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp backend_db_1
I really cannot figure out the issue, so am I missing something?
I write this to save anyone in future from the same issue.
After countless tries, I started thinking that nothing was wrong from the pure docker perspective: I was right.
SOLUTION: My only suspect was related to the execution inside a Virtual Machine, so executing the same docker image on the host worked like a charm!
The networking issue was related to the VM (VirtualBox Ubuntu 20.04)
I do not know if there is a way to work with docker-compose inside a VM, so any suggestion is appreciated.
You said in a comment:
The command I run is the following: docker run -it --entrypoint /bin/sh backend_web
Docker Compose creates several Docker resources, including a default network. If you separately docker run a container it doesn't see any of these resources. The docker run container is on the "default bridge network" and can't use present-day Docker networking capabilities, but the docker-compose container is on a separate "user-defined bridge network" named backend_default. That's why you're seeing a couple of the symptoms you do: the two networks have separate IPv4 CIDR ranges, and Docker's container DNS resolution only happens for the current network.
There's no reason to start a container with an interactive shell and then start your application within that (any more than you don't normally run python and then manually call main() from its REPL). Just start the entire application:
docker-compose up -d
If you do happen to need an interactive shell to debug your container setup or to run some manual tasks like database migrations, you can use docker-compose run for this. This honors most, but not all, of the settings in the docker-compose.yml file. In particular you can't docker-compose run an interactive shell and start your application from it, since it ignores ports:.
# Typical use: run database migrations
docker-compose run web \
./manage.py migrate
# For debugging: run an interactive shell
docker-compose run web bash

deploy nuxtjs application to GCP, but it gives server error?

I'm new to GCP (google cloud platform) I'm facing this problem, Backend dev created an Apache server on gcp, and then I cloned my repo on the server through VM, build it and then deployed it after following countless tutorials.. but while deploying it gives
Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable.
when i go to the generated link which is https://vetution.oa.r.appspot.com/ it gives server error, I've searched a lot but I failed.
Have I done something wrong or the app.yaml file should have different configurations.
anyway here it is
runtime: nodejs12
instance_class: F2
handlers:
- url: /_nuxt
static_dir: .nuxt/dist/client
secure: always
- url: /(.*\.(gif|png|jpg|ico|txt))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg|ico|txt)$
secure: always
- url: /.*
script: auto
secure: always
env_variables:
HOST: '0.0.0.0'
NODE_ENV: 'production'
And It gives me this error on deploying now
please, Help me I'm very frustrated.
The error states that, your app failed to start because it's not listening to a port as you may not have configure it to your app. This topic is answered on this Stackoverflow thread.
You mentioned that you followed countless tutorials, it is possible that you are using Cloud Run and App Engine interchangeably, which are 2 separate serverless products. Please evaluate on your end which platform is right for your app and use case.
Currently, there is not much debugging info to your question but either way, make sure that you configure your app's port to listen to incoming request/s, it can be port 8080 or can be any of your choice. Also, check your GCP logs, backend issues and server errors can be seen and monitored by simply looking at the logs for App Engine or Cloud Run.
Check Cloud Run configuring the container ports, for port configuration.

How to connect to spanner emulator from a docker container

I am able to connect to the spanner emulator directly from my local machine but I am having trouble when trying to connect to it from a docker container.
I have the following two services in my compose file:
version: '3.7'
services:
serviceA:
image: "test
depends_on:
- spanner-emulator
environment:
SPANNER_EMULATOR_HOST: localhost:9010
spanner-emulator:
image: spanner_image
ports:
- 9010:9010
- 9020:9020
- 9515:9515
When I spin up the serviceA, I am able to use gcloud to run queries on my local spanner emulator. But when I try to run commands from within the serviceA container I get last exception: 503 failed to connect to all addresses.
The commands that I am trying to run (which work outside the container on my machine directly)
spanner_client = spanner.Client(project="my-proj")
instance = spanner_client.instance("Emulator")
database = instance.database("my-db")
with database.snapshot() as snapshot:
results = snapshot.execute_sql("SELECT Name, Version FROM test1")
for row in results:
print(u"Name: {}, Version: {}".format(*row))
Help appreciated!
Dumb mistake. I am able to connect to the emulator from the docker container when I changed SPANNER_EMULATOR_HOST to spanner-emulator:9010

Using Traefik with EC2, how does frontend rule change url

I am new to using proxy, so I didnt quite follow why this isn't working. Not sure if this a Trafeik question, or a simple "I dont know how routing works" question
I followed the Traefik tutorial as show on their website here : https://docs.traefik.io/
Their docker-compose.yml looks like this:
version: '3'
services:
reverse-proxy:
image: traefik # The official Traefik docker image
command: --api --docker # Enables the web UI and tells Traefik to listen to docker
ports:
- "80:80" # The HTTP port
- "8080:8080" # The Web UI (enabled by --api)
volumes:
- /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
whoami:
image: containous/whoami # A container that exposes an API to show its IP address
labels:
- "traefik.frontend.rule=Host:whoami.docker.localhost"
So now I wanted to run this same yml file on my ec2 instance. I make a change to the last line so that it looks like this instead:
- "traefik.frontend.rule=Host:whoami.docker.<ec2-XXX>.<region>.compute.amazonaws.com"
So I assumed that if I visited http://whoami.docker.<ec2-XXX>.<region>.compute.amazonaws.com, I would see my whoami app's response. However, I get a response from my ISP that that wesbite does not exist. If I access http://<ec2-XXX>.<region>.compute.amazonaws.com:8080 I can see my Traefik console fine.
I think its got to do with web addresses, and you can only have two items before the website, like x.y.website.com, and the url I am using to access my ec2 is already using those two slots. I am unsure what to search for.
Do I need to register a site/ buy a domain first?
How would I connect this site to my ec2 instance?
Was I correct as to why http://whoami.docker.<ec2-XXX>.<region>.compute.amazonaws.com was not working?