docker prometheus not able to access docker kafka_exporter - docker

version: '3.4'
services:
kafka_exporter:
image: danielqsj/kafka-exporter
command: --kafka.server=xx.xx.xx.xx:9092 --kafka.server=xx.xx.xx.xx:9092
ports:
- 9308:9308
links:
- prometheus
prometheus:
image: prom/prometheus
ports:
- 9090:9090
volumes:
- ./mount/prometheus:/etc/prometheus
command: --config.file=/etc/prometheus/prometheus.yml
Above is my docker-compose.yml file.
I am able to spin up both the images.
However, I am not able to access localhost:9308 (kafka_Exporter) from localhost:9090 (prometheus)
Do I need to link/network images?

It should be container_name:port
kafka_exporter:9308

Related

Why is my Portainer Docker Compose creating a new volume

I installed Portainer via Docker Compose. I followed basic directions where I created a portainer_data docker volume:
docker create volume portainer_data
Then I used the following Docker Compose file to setup portainer and portainer agent:
version: '3.3'
services:
portainer-ce:
ports:
- '8000:8000'
- '9443:9443'
container_name: portainer
restart: unless-stopped
command: -H tcp://agent:9001 --tlsskipverify
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data
image: 'portainer/portainer-ce:latest'
agent:
container_name: agent
image: portainer/agent:latest
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/lib/docker/volumes:/var/lib/docker/volumes
ports:
- "9001:9001"
volumes:
portainer_data:
But then I see this inside Portainer when I look at the volumes:
What is wrong in my configuration that it creates a new volume and ignores the one I setup?
Thanks.
docker by default prepends the project name to volume name, this is an expected behaviour https://forums.docker.com/t/docker-compose-prepends-directory-name-to-named-volumes/32835 to avoid this you have two options you can set project name when you run the docker-compose up or update the docker-compose.yml file to use the external volume you created
version: '3.3'
services:
portainer-ce:
ports:
- '8000:8000'
- '9443:9443'
container_name: portainer
restart: unless-stopped
command: -H tcp://agent:9001 --tlsskipverify
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data
image: 'portainer/portainer-ce:latest'
agent:
container_name: agent
image: portainer/agent:latest
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/lib/docker/volumes:/var/lib/docker/volumes
ports:
- "9001:9001"
volumes:
portainer_data:
name: portainer_data
external: false

Grafana fails to run from Docker

I'm trying to run Grafana with Prometheus using docker compose.
However I keep getting the following error from Graphana container:
service init failed: html/template: pattern matches no files: /usr/share/grafana/public/emails/*.html, emails/*.txt
Here's the content of docker-compose.yml:
version: "3.3"
volumes:
prometheus_data: {}
grafana_data: {}
services:
prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
expose:
- 9090
volumes:
- ./infrastructure/config/prometheus/:/etc/prometheus/
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.retention.time=1y'
graphana:
image: grafana/grafana:latest
user: '472'
volumes:
- grafana_data:/var/lib/grafana
- ./infrastructure/config/grafana/grafana.ini:/etc/grafana/grafana.ini
- ./infrastructure/config/grafana/datasource.yml:/etc/grafana/provisioning/datasources/datasource.yml
ports:
- 3000:3000
links:
- prometheus
As for the content of grafana.ini and datasource.yml files I'm using the default Grafana configuration files that are provided in its official Github repository.
The answer here suggests that it can be resolved by setting the correct permissions to grafana config folder. However, I tried giving full permission (with chmod -R 777 command) to the ./infrastructure/config/grafana folder and it didn't resolve the issue.
If anyone can provide any help on how to solve this problem it'd be greatly appreciated!
USE THIS in your docker_compose
grafana:
hostname: 'grafana'
image: grafana/grafana:latest
restart: always
tmpfs:
- /run
volumes:
- grafana_data:/var/lib/grafana
- ./infrastructure/config/grafana/grafana.ini:/etc/grafana /grafana.ini
- ./infrastructure/config/grafana/datasource.yml:/etc/grafana/provisioning/datasources/datasource.yml
ports:
- "3000:3000"

Access localhost and docker network using docker-compose

I have two different services running in a single docker-compose file. I talk to each service by referring to the service name of the containers.
Now I want my container A to access localhost as well. For this when I added the configuration of 'network_mode=host', but this creates an error now stating that container A cannot talk to container B.
version: '2'
services:
rocketchat:
image: myimage
environment:
- MONGO_URL=mongodb://mongo:27017/dbname
depends_on:
- mongo
ports:
- 3000:3000
network_mode: host
mongo:
image: mongo:3.2
ports:
- 27017:27017
For each compose file docker-compose creates a network so in this case, should I manually assign the containers to a dedicated network as well? Or is there any workaround to access both the networks?
try to add links :
version: '2'
services:
rocketchat:
image: myimage
environment:
- MONGO_URL=mongodb://mongo:27017/dbname
depends_on:
- mongo
ports:
- 3000:3000
links:
- mongo
#network_mode: host
mongo:
image: mongo:3.2
ports:
- 27017:27017
and you do not need network_mode: host if you use the links
EDIT - Other solution:
version: '2'
services:
rocketchat:
image: myimage
environment:
- MONGO_URL=mongodb://localhost:27017/dbname
depends_on:
- mongo
ports:
- 3000:3000
network_mode: host
mongo:
image: mongo:3.2
ports:
- 27017:27017
network_mode: host

How to persist data in a dockerized DynamoDB using volumes

My docker compose file has two containers and looks like this
version: '3'
services:
dynamodb:
image: amazon/dynamodb-local
ports:
- '8000:8000'
networks:
- testnetwork
audit-server:
image: audit-dynamo
environment:
DYNAMO_URL: 'http://0.0.0.0:8000'
command: node app.js
ports:
- '3000:3000'
depends_on:
- dynamodb
# restart: always
networks:
- testnetwork
networks:
testnetwork:
My goal is to mount local data to some volume. currently losing data on docker-compose down
So that image uses by default in-memory dynamodb (what you can find by running docker inspect on that image)
"CMD [\"-jar\" \"DynamoDBLocal.jar\" \"-inMemory\"]"
So if you want to keep your data, you need to do something like this in your docker-compose:
version: '3'
volumes:
dynamodb_data:
services:
dynamodb:
image: amazon/dynamodb-local
command: -jar DynamoDBLocal.jar -sharedDb -dbPath /home/dynamodblocal/data/
volumes:
- dynamodb_data:/home/dynamodblocal/data
ports:
- "8000:8000"
You can try this docker-compose config:
version: '3'
volumes:
dynamodb_data:
services:
dynamodb:
image: amazon/dynamodb-local
command: -jar DynamoDBLocal.jar -sharedDb -dbPath /home/dynamodblocal
volumes:
- dynamodb_data:/home/dynamodblocal
ports:
- "8000:8000"
To preserve data across docker installations create volume using docker.
docker volume create --driver local --opt type=none \
--opt device=/var/opt/dynamodb_data --opt o=bind dynamodb_data
use external option:
version: "3"
volumes:
dynamodb_data:
external: true
services:
dynamodb-local:
image: amazon/dynamodb-local
command: ["-jar", "DynamoDBLocal.jar", "-sharedDb", "-dbPath", "/home/dynamodblocal/data"]
volumes:
- dynamodb_data:/home/dynamodblocal/data

How to see other container from one container in docker?

I have compose file as follows;
redis:
image: redis
ports:
- "6379:6379"
php:
build: .
image: php:fpm
volumes:
- ./code:/var/www/html
links:
- redis:redis
networks:
- code-network
I'm entering into php container with the following command.
docker exec -it php_id /bin/bash
but I can't run "redis-cli" command in this container. What do I need to do to run it.
I added "links" parameter to compose file but it didn't.
You are putting the php-fpm container in a network of its own. Here is a fixed compose file:
version: "3"
services:
redis:
image: redis
ports:
- "6379:6379"
php:
build: .
image: php:fpm
volumes:
- ./code:/var/www/html
networks:
- code-network
- default
networks:
code-network:
See this for more info on compose networking.
About the redis-cli issue: You'd need to add the appropriate repository on the php-fpm container and then install it. As you are using the php:fpm image, you propably want to use redis with some php-application, therefore you don't need debians redis-cli package, but rather the php-extension.
See this post for more info.

Resources