How to setup Redis Commander and Docker? - docker

I've tried the 'with docker' docs here but it's not working from the localhost:7000, localhost:8081, or any other port I use. What am I missing?
REDIS_PORT=6379
### Redis ################################################
redis:
container_name: redis
hostname: redis
build: ./redis
volumes:
- ${DATA_PATH_HOST}/redis:/data
ports:
- "${REDIS_PORT}:6379"
networks:
- backend
### REDISCOMMANDER ################################################
redis-commander:
container_name: rediscommander
hostname: redis-commander
image: rediscommander/redis-commander:latest
restart: always
environment:
- REDIS_HOSTS=local:redis:6379
ports:
- "7000:80"
networks:
- frontend
- backend
depends_on:
- redis
Docker ps gives me:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
042c9a2e918a rediscommander/redis-commander:latest "/usr/bin/dumb-init …" About a minute ago Up About a minute (healthy) 8081/tcp, 0.0.0.0:7000->80/tcp rediscommander
86bc8c1ca5ff laradock_redis "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:6379->6379/tcp redis
Docker logs rediscommander gives me:
$ docker logs rediscommander
Creating custom redis-commander config '/redis-commander/config/local-production.json'.
Parsing 1 REDIS_HOSTS into custom redis-commander config '/redis-commander/config/local-production.json'.
node ./bin/redis-commander
Using scan instead of keys
No Save: false
listening on 0.0.0.0:8081
access with browser at http://127.0.0.1:8081
Redis Connection redis:6379 using Redis DB #0

Redis commader is listening on port 8081 in container. That is why you should change port binding to
ports:
- "7000:8081"
in redis commander block and access it via localhost:7000.

Related

coturn docker container error Temporary failure in name resolution

i am trying to run coturn in docker folowing this tutorial and using mongodb as a selected database
here is docker-compose of coturn with mongodb
docker-compose-mongodb.yml
version: "3"
services:
# MongoDB
mongodb:
image: mongo
restart: unless-stopped
container_name: docker-mongo
ports:
- "27017:27017"
volumes:
- mongodb-data:/data/db
env_file:
- mongodb/mongodb.env
networks:
- backend
# Coturn
coturn:
build:
context: ../
dockerfile: ./docker/coturn/debian/Dockerfile
restart: always
volumes:
- ./coturn/turnserver.conf:/etc/turnserver.conf:ro
- ./coturn/privkey.pem:/etc/ssl/private/privkey.pem:ro
- ./coturn/cert.pem:/etc/ssl/certs/cert.pem:ro
ports:
## STUN/TURN
- "3478:3478"
- "3478:3478/udp"
- "3479:3479"
- "3479:3479/udp"
- "80:80"
- "80:80/udp"
## STUN/TURN SSL
- "5349:5349"
- "5349:5349/udp"
- "5350:5350"
- "5350:5350/udp"
- "443:443"
- "443:443/udp"
# Relay Ports
# - "49152-65535:49152-65535"
# - "49152-65535:49152-65535/udp"
networks:
- frontend
- backend
depends_on:
- mongodb
env_file:
- coturn/coturn.env
# DB
- mongodb/mongodb.env
volumes:
mongodb-data:
networks:
frontend:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.16.238.0/24
backend:
internal: true
and here is the coturn (dockerFile)[https://github.com/coturn/coturn/blob/master/docker/coturn/debian/Dockerfile]
i am using the file as it is
now when i run
docker-compose -f docker-compose-mongodb.yml up
and here is
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
85eaa0b1d14e docker_coturn "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:80->80/udp, :::80->80/tcp, :::80->80/udp, 0.0.0.0:443->443/tcp, 0.0.0.0:443->443/udp, :::443->443/tcp, :::443->443/udp, 0.0.0.0:3478-3479->3478-3479/tcp, 0.0.0.0:3478-3479->3478-3479/udp, :::3478-3479->3478-3479/tcp, :::3478-3479->3478-3479/udp, 0.0.0.0:5349-5350->5349-5350/tcp, 0.0.0.0:5349-5350->5349-5350/udp, :::5349-5350->5349-5350/tcp, :::5349-5350->5349-5350/udp docker_coturn_1
4226a039f1ea mongo "docker-entrypoint.s…" 3 minutes ago Up 3 minutes docker-mongo
when i try to ping
nc -zvv docker-mongo 27017
i am getting
nc: getaddrinfo for host "docker-mongo" port 27017: Temporary failure in name resolution
and
nc -zvv docker_coturn_1 3478
and its also giving the same error
nc: getaddrinfo for host "docker_coturn_1" port 3478: Temporary failure in name resolution
how can i resolve this error ? i am using ubuntu 20.04 lts

How to add image name to docker-compose up

I have a docker-compose file that I use the image block in the service to name. For example
version: '3'
services:
redis:
image: redis
restart: unless-stopped
ports:
- "6379"
worker:
image: worker:production
build: .
user: root
command: celery -A ExactEstate worker --loglevel=info
env_file: ./.env.prod
restart: unless-stopped
links:
- redis
depends_on:
- redis
beats:
image: beats:production
build: .
user: root
command: celery --pidfile= -A ExactEstate beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler
env_file: ./.env.prod
restart: unless-stopped
links:
- redis
depends_on:
- redis
web:
image: web:production
build: .
user: root
command: daphne -b 0.0.0.0 -p 8000 ExactEstate.asgi:application
ports:
- "8000:8000"
env_file: ./.env.prod
restart: unless-stopped
links:
- redis
- worker
- beats
depends_on:
- redis
- worker
- beats
This gives a docker ps of:
0ad78269a9ce beats:production "celery --pidfile= -…" 7 minutes ago Up 7 minutes exactestate_beats_1
1a44f7c98b50 worker:production "celery -A ExactEsta…" 7 minutes ago Up 7 minutes exactestate_worker_1
f3a09723ba66 redis "docker-entrypoint.s…" 7 minutes ago Up 7 minutes 0.0.0.0:32769->6379/tcp exactestate_redis_1
Let's suppose I also have built containers from a different compose file (i.e. staging) How can I use docker-compose to on pull up the exact service/image I want?
For example: docker-compose up web:production or docker-compose up web:staging
You can achieve this by using environment variables. Variables for docker-compose up could be passed as .env file or set by export (or set on Windows) command (docker documentation).
web:
image: web:production
Should be changed to
web:
image: web:${ENV}
And then you can run your application by running
$ export ENV=production && docker-compose up
Or you can create .env file containing line ENV=production. Then you can simply run application with docker-compose up.

docker-compose creating multiple set of services

I'm trying to create 3 mattermost services on 1 AWS EC2 machine.
Let me explain further with more texts:
When I run docker-compose up -d, I get a service whose structure is like this:
How can I modify the docker related scripts so that I can create 3 sets of service?
I've tried docker-compose up --scale app=3 --scale web=3 --scale db=3. But I can't find any way to specify different port for each of the App container.
The only solution I've found is:
Create 3 copies of mattermost-docker folder.
Change the App port and database connection information.
Run docker-compose up -d 3 times in mattermost-docker1, mattermost-docker2, and mattermost-docker3 separately.
But this solution creates a lot of duplicated files. I don't like it.
Anyone knows how to create 3 sets of mattermost services?
You need to specify a port range in docker compose:
For example, for 10 container scalling:
version: '3'
services:
web:
...
ports:
- "80-90:443"
app:
...
ports:
- "8000-8010"
Note that you don't need to change port inside container (443, 444, 445). You can use the same, and furthermore that's recommended, because although you use different containers in a port range, is easier if they use the same nginx configuration.
This starts sets of services using 3 separate databases (nginx and mongo used as example).
version: '3'
services:
web1:
container_name: web1
image: nginx:latest
ports:
- 8080:8080
app1:
container_name: app1
image: nginx:latest
ports:
- "8081:8081"
db1:
container_name: db1
image: mongo
ports:
- 27017
web2:
container_name: web2
image: nginx:latest
ports:
- 8082:8082
app2:
container_name: app2
image: nginx:latest
ports:
- "8083:8083"
db2:
container_name: db2
image: mongo
ports:
- 27018
web3:
container_name: web3
image: nginx:latest
ports:
- 8084:8084
app3:
container_name: app3
image: nginx:latest
ports:
- "8085:8085"
db3:
container_name: db3
image: mongo
ports:
- 27019
Local Test:
NAMES STATUS PORTS IMAGE
db2 Up About a minute 27017/tcp, 0.0.0.0:32803->27018/tcp mongo
web1 Up About a minute 80/tcp, 0.0.0.0:32802->8080/tcp nginx:latest
db1 Up About a minute 0.0.0.0:32801->27017/tcp mongo
app1 Up About a minute 80/tcp, 0.0.0.0:32800->8081/tcp nginx:latest
app3 Up About a minute 80/tcp, 0.0.0.0:32798->8085/tcp nginx:latest
db3 Up About a minute 27017/tcp, 0.0.0.0:32799->27019/tcp mongo
app2 Up About a minute 80/tcp, 0.0.0.0:32797->8083/tcp nginx:latest
web3 Up About a minute 80/tcp, 0.0.0.0:32796->8084/tcp nginx:latest
web2 Up About a minute 80/tcp, 0.0.0.0:32795->8082/tcp nginx:latest

Why docker-compose do not use port binding as expected?

I'm using this docker-compose config for running a classic nodejs app + mysql + redis:
version: '3'
services:
app:
container_name: app
restart: always
build:
context: ./app/
depends_on:
- db
- redis
- elasticsearch
links:
- db
- redis
- elasticsearch
ports:
- "127.0.0.1:${APP_PORT}:${APP_PORT}"
environment:
- "PORT=${APP_PORT}"
- "MYSQL_PORT=${MYSQL_PORT}"
- "REDIS_PORT=${REDIS_PORT}"
redis:
container_name: redis
image: "redis:3-alpine"
restart: always
ports:
- "127.0.0.1:${REDIS_PORT}:6379"
db:
container_name: db
image: mariadb:10.0.30
restart: always
volumes:
- "${MYSQL_DATA_LOCATION}/data:/var/lib/mysql:delegated"
- "${MYSQL_DATA_LOCATION}/my.cnf:/etc/mysql/my.cnf:ro"
ports:
- "127.0.0.1:${MYSQL_PORT}:3306"
environment:
- "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}"
- "MYSQL_USER=${MYSQL_USER}"
- "MYSQL_PASSWORD=${MYSQL_PASSWORD}"
- "MYSQL_DATABASE=${MYSQL_DATABASE}"
I'm also using a .env file containing the following values:
APP_PORT=5000
MYSQL_PORT=3306
REDIS_PORT=6379
And I start the application with
docker-compose up -d
Everything runs fine this way. I can change the mysql port without error, but if I change the redis port to something else than the original port, I have the following error in the app, when I use this config:
redis.createClient({host: 'redis', port: process.env.REDIS_PORT });
I get the following message:
Error: Redis connection to redis:5555 failed - connect ECONNREFUSED 172.18.0.3:5555
Whereas the connection between the db and the app works correctly :s
In docker ps I can see that the machine started with the expected config:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9c594c6d98b8 nginx:mainline-alpine "nginx -g 'daemon of…" 33 seconds ago Up 39 seconds 0.0.0.0:2000->80/tcp webproxy
62d1f917d7ff app "npm run docker-debug" 36 seconds ago Up 42 seconds 127.0.0.1:5000->5000/tcp, 127.0.0.1:9222->9222/tcp app
7c982d543a7d mariadb:10.0.30 "docker-entrypoint.s…" 39 seconds ago Up 45 seconds 127.0.0.1:4000->3306/tcp db
9dd13967b37d redis:3 "docker-entrypoint.s…" 39 seconds ago Up 44 seconds 127.0.0.1:5555->6379/tcp redis
I can see here that the db is mapped from 4000 to 3306, which works, but the redis mapping from 5555 to 6379 is ignored. And if I manually change the port in the app connection to port 6379, it does work...
Is there something missing in my configuration ?
the redis is running inside the container on port 6379 period (if you dont change the port in its config). On your host you map port 5555 to redis container 6379. All services in docker-compose are visible to each other and you dont even need to EXPOSE those ports to host. In your app settings if you access the redis by redis://redis:6379 will work or with the exposed port redis://HOST_IP:5555 will work too

consumer: Cannot connect to amqp://user:**#localhost:5672//: [Errno 111] Connection refused

I am trying to build my airflow using docker and rabbitMQ. I am using rabbitmq:3-management image. And I am able to access rabbitMQ UI, and API.
In airflow I am building airflow webserver, airflow scheduler, airflow worker and airflow flower. Airflow.cfg file is used to config airflow.
Where I am using broker_url = amqp://user:password#127.0.0.1:5672/ and celery_result_backend = amqp://user:password#127.0.0.1:5672/
My docker compose file is as follows
version: '3'
services:
rabbit1:
image: "rabbitmq:3-management"
hostname: "rabbit1"
environment:
RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
RABBITMQ_DEFAULT_USER: "user"
RABBITMQ_DEFAULT_PASS: "password"
RABBITMQ_DEFAULT_VHOST: "/"
ports:
- "5672:5672"
- "15672:15672"
labels:
NAME: "rabbitmq1"
webserver:
build: "airflow/"
hostname: "webserver"
restart: always
environment:
- EXECUTOR=Celery
ports:
- "8080:8080"
depends_on:
- rabbit1
command: webserver
scheduler:
build: "airflow/"
hostname: "scheduler"
restart: always
environment:
- EXECUTOR=Celery
depends_on:
- webserver
- flower
- worker
command: scheduler
worker:
build: "airflow/"
hostname: "worker"
restart: always
depends_on:
- webserver
environment:
- EXECUTOR=Celery
command: worker
flower:
build: "airflow/"
hostname: "flower"
restart: always
environment:
- EXECUTOR=Celery
ports:
- "5555:5555"
depends_on:
- rabbit1
- webserver
- worker
command: flower
I am able to build images using docker compose. However, I am not able to connect my airflow scheduler to rabbitMQ. I am getting following error:
consumer: Cannot connect to amqp://user:**#localhost:5672//: [Errno
111] Connection refused.
I have tried using 127.0.0.1 and localhost both.
What I am doing wrong ?
From within your airflow containers, you should be able to connect to the service rabbit1. So all you need to do is to change amqp://user:**#localhost:5672//: to amqp://user:**#rabbit1:5672//: and it should work.
Docker compose creates a default network and attaches services that do not explicitly define a network to it.
You do not need to expose the 5672 & 15672 ports on rabbit1 unless you want to be able to access it from outside the application.
Also, generally it is not recommended to build images inside docker-compose.
I solved this issue by installing rabbitMQ server into my system with command sudo apt install rabbitmq-server.

Resources