Bad Gateway came out when I tried to connect Grafana and InfluxDB on Docker

screencapture-localhost-3000-datasources-edit-6-2021-01-12-20_21_50.png

When I tried the tutorial that came out by googled "Grafana InfluxDB Docker", the story that was troubled by the above Bad Gateway. The bottom line was that I didn't understand the combination of URL and Access correctly.

Implementation environment

I launched a Grafana and InfluxDB container on Docker on my local PC and tried to configure InflxDB from Grafana's Data Sources. Write the following Docker-compose.yml and execute it.

version: "3"
services:
  influxdb:
    image: influxdb:latest
    ports:
      - "8086:8086"
    volumes:
      - ./data/influxdb:/var/lib/influxdb

  grafana:
    image: grafana/grafana:latest
    ports:
      - "3000:3000"
    volumes:
      - ./data/grafana:/var/lib/grafana
    depends_on:
      - influxdb

I like volumes for feasibility, but this time I will create a "data" folder in the same hierarchy as docker-compose.yml, and create an "influxdb" folder and a "grafana" folder under it.

Access InfluxDB with docker command, create a new database (sample in this case) and measurement, then access Grafana with " http: // localhost: 3000 " and Data Sources of Configuration When I entered the information to add more InfluxDB and even executed "Save & Test", the "InfluxDB Error: Bad Gateway" as shown at the beginning occurred.

Solution (1) Change Access from Server to Browser (not recommended)

This is the solution that I was able to connect while playing with various settings. If you understand the meaning after that, this ① is deprecated and you should carry out ② described later, so it is only for reference. スクリーンショット 2021-01-12 20.54.22.png If you want to establish a connection with the URL " https: // localhost: 8086 ", change Access from " Server " to " Browser " after" Save & Test ". , "Data source is working" and now connected.

By the way, what is this Access? If you select "Help" on the right, the following description will be displayed. スクリーンショット 2021-01-12 20.58.44.png In summary, I understand that: -** Server ** attempts access via Grafana's backend (internal communication) -** Browser ** tries to access directly from the browser (external communication)

In other words, the reason I stumbled this time is that the URL is "localhost: 8086" when ** Server **, so ** I tried to access the 8086 port on the Grafana container **, so Bad Gateway occurred. It will be.

However, in solution (1), localhost (local PC itself) is now accessed as external communication instead of internal communication, so it is possible to connect. However, in actual cases, there are almost no cases where the database layer like InfluxDB can be accessed from the outside, and it is desirable to be able to access the DB by internal communication.

Therefore, this time, I made it accessible with the following solution.

Solution (2) Change the URL to a name (address) for internal communication

This time, since the Grafana container and InfluxDB container are started from Docker compose, it depends on the description of docker-compose.yml and the directory name, but this time it will be in the following state as an example.

 $ docker-compose ps
           Name                      Command           State           Ports
-------------------------------------------------------------------------------------
influxdb_grafana_grafana_1    /run.sh                  Up      0.0.0.0:3000->3000/tcp
influxdb_grafana_influxdb_1   /entrypoint.sh influxd   Up      0.0.0.0:8086->8086/tcp

In the above case, the container name of InfluxDB will be "influxdb_grafana_influxdb_1". In docker-compose, name resolution can be done by default with each other's container name from network, so by using this "influxdb_grafana_influxdb_1" as the URL name, Access will be able to connect even with ** Server **. In this example, the URL is http: // influxdb_grafana_influxdb_1: 8086.

screencapture-localhost-3000-datasources-edit-6-2021-01-12-21_13_50.png

Recommended Posts

Bad Gateway came out when I tried to connect Grafana and InfluxDB on Docker
I tried to link grafana and postgres [docker-compose]
I started MySQL 5.7 with docker-compose and tried to connect
I tried to create React.js × TypeScript × Material-UI on docker environment
I tried to figure out the flow when performing image analysis with Vision Framework and Core ML
I tried migrating the portfolio created on Vagrant to the Docker development environment
I tried running Docker on Windows Server 2019
Microservices 101-I tried putting Docker on Ubuntu-
I tried to build AdoptOpenjdk 11 on CentOS 7
What is Docker? I tried to summarize
[First environment construction] I tried to create a Rails 6 + MySQL 8.0 + Docker environment on Windows 10.
A story when I tried to make a video by linking Processing and Resolume
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
I installed Docker on EC2 and started it
I tried running Ansible on a Docker container
I tried to link JavaFX and Spring Framework.
I tried installing docker on an EC2 instance
I tried using Wercker to create and publish a Docker image that launches GlassFish 5.
The story that did not disappear when I tried to delete mysql on ubuntu
Notes on errors that occur when installing the JDK and countermeasures that I have tried
A story I was addicted to when getting a key that was automatically tried on MyBatis
I tried to read and output CSV with Outsystems
I tried to summarize the state transition of docker
I tried to integrate AWS I oT button and Slack
I tried using YOLO v4 on Ubuntu and ROS
I tried using Docker Desktop for Windows on Windows 10 Home
Rails6 I tried to introduce Docker to an existing application
I tried to chew C # (reading and writing files)
I tried to find out what changed in Java 9
I tried to build an environment using Docker (beginner)
[It takes 3 minutes] When I tried to install VS Code on Ubuntu 18.04, it was unexpectedly easy.
[Rails 6.0, Docker] I tried to summarize the Docker environment construction and commands necessary to create a portfolio
When I set webpack.config.js to run vue.js on rails6, I got too many errors and grass
When I tried to run Azure Kinect DK with Docker, it was blocked by EULA
[Terraform] When I try to build an Azure resource on a Windows machine, it will time out, so I solved it with Docker.