It was not possible to connect to the redis server - docker

I am trying to compose my project, but got this error:
It was not possible to connect to the Redis server(s). UnableToConnect
on localhost:6379/Interactive
How can I fix or find a problem? Thank you.
docker-compose.yml:
version: '3.4'
services:
catalogdb:
image: mongo
cartdb:
image: redis:alpine
eshop.catalog.api:
image: ${DOCKER_REGISTRY-}eshopcatalogapi
build:
context: .
dockerfile: EShop.Catalog.API/Dockerfile
eshop.cart.api:
image: ${DOCKER_REGISTRY-}eshopcartapi
build:
context: .
dockerfile: EShop.Cart.API/Dockerfile
volumes:
mongo_data:
docker-compose.override.yml:
version: '3.4'
services:
catalogdb:
container_name: catalogdb
restart: always
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db
cartdb:
container_name: cartdb
restart: always
ports:
- "6379:6379"
eshop.catalog.api:
container_name: catalog.api
environment:
- ASPNETCORE_ENVIRONMENT=Development
- "DatabaseSettings:ConnectionString=mongodb://catalogdb:27017"
depends_on:
- catalogdb
ports:
- "8000:80"
eshop.cart.api:
container_name: cart.api
environment:
- ASPNETCORE_ENVIRONMENT=Development
- "CacheSettings:ConnectionString=basketdb:6379"
depends_on:
- cartdb
ports:
- "8001:80"

Related

services.mysql Additional property website is not allowed

version: '3.8'
volumes:
datafiles:
services:
mysql:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
container_name: mysql_ecommerce
environment:
- MYSQL_ROOT_PASSWORD=12345
- MYSQL_TCP_PORT=3308:3306
volumes:
- datafiles:/var/lib/mysql
restart: always
website:
container_name: web_ecommerce
build:
context: .
dockerfile: Dockerfile
enviroment:
- MYSQL_DBHOST=mysql
- MYSQL_DBPORT=3306
- MYSQL_DBUSER=root
- MYSQL_DBPASS=12345
- MYSQL_DBNAME=
ports:
- 8082:80
- 8083:443
depends_on:
- mysql
You may need to check your docker-compose file and ensure it follows the correct indentation.
version: '3.8'
services:
mysql:
website:

Request to MX server from a docker container

Context
Our solution send emailing campaign, and some email provider makes temporary blacklist because we used inexistant email addresses (they may be created/imported by any user)
Solution
I try to implement a email checker based on https://www.codexworld.com/verify-email-address-check-if-real-exists-domain-php/
Problem
From my local computer, this script works (when my IP is not temporary blacklisted) but from my Docker Container stream_socket_client or even telnet always times out.
As I see, MX servers always time out non verified requester but how can I make it work from my docker container?
I've no specific docker configuration for the port 25.
Thank you
docker-compose.yml
# Base docker-compose file to run required services: Adminer, MySQL, and Redis
version: '3.7'
services:
adminer:
image: adminer:latest
ports:
- "8080:8080"
database:
image: mysql:8.0
volumes:
- db_data:/var/lib/mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
cap_add: [ SYS_NICE ] # https://github.com/docker-library/mysql/issues/303
command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_general_ci', '--lower_case_table_names=1']
redis:
image: redis:alpine
expose:
- "6379"
redisinsight:
image: redislabs/redisinsight
ports:
- "8081:8001"
reverse-proxy:
image: nginx:alpine
depends_on:
- backend
- frontend
volumes:
- ./../../../backend/infra/etc/nginx/dev.conf:/etc/nginx/nginx.conf
ports:
- "80:80"
backend:
build:
context: ./../..
dockerfile: container/dev/backend.dockerfile
expose:
- "80"
volumes:
- {...}
depends_on:
- database
frontend:
build:
context: ./../..
dockerfile: container/dev/frontend.dockerfile
expose:
- "3000"
volumes:
- {...}
tty: true # required to keep yarn running (https://stackoverflow.com/a/61050994)
volumes:
# Contains the database's data
db_data: {}
# Base docker-compose file to run required services: Adminer, MySQL, and Redis
version: '3.7'
services:
adminer:
image: adminer:latest
ports:
- "8080:8080"
database:
image: mysql:8.0
volumes:
- db_data:/var/lib/mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
cap_add: [ SYS_NICE ] # https://github.com/docker-library/mysql/issues/303
command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_general_ci', '--lower_case_table_names=1']
redis:
image: redis:alpine
expose:
- "6379"
redisinsight:
image: redislabs/redisinsight
ports:
- "8081:8001"
reverse-proxy:
image: nginx:alpine
depends_on:
- backend
- frontend
volumes:
- ./../../../backend/infra/etc/nginx/dev.conf:/etc/nginx/nginx.conf
ports:
- "80:80"
backend:
build:
context: ./../..
dockerfile: container/dev/backend.dockerfile
expose:
- "80"
volumes:
- {...}
depends_on:
- database
frontend:
build:
context: ./../..
dockerfile: container/dev/frontend.dockerfile
expose:
- "3000"
volumes:
- {...}
tty: true # required to keep yarn running (https://stackoverflow.com/a/61050994)
volumes:
# Contains the database's data
db_data: {}
backend.dockerfile is an ubuntu with git, mysql-client, php

"Unable to find template" with Docker

I created a Symfony environment with Docker. I then included this file in my web project (skeleton website). But when I try to access my base.html.twig page located in a main folder from the controller, I get this error:
Unable to find template "main/base.html.twig" (looked into: /var/www/templates, /var/www/vendor/symfony/twig-bridge/Resources/views/Form).
How can I solve the problem? I have version 5 of Symfony.
Here is the content of my docker-compose file:
version: '3'
services:
php:
container_name: "php-fpm"
build:
context: ./php
environment:
- APP_ENV=${APP_ENV}
- APP_SECRET=${APP_SECRET}
volumes:
- ${APP_FOLDER}:/var/www
networks:
- dev
nginx:
container_name: "nginx"
build:
context: ./nginx
volumes:
- ${APP_FOLDER}:/var/www
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./logs:/var/log/nginx/
depends_on:
- php
ports:
- "80:80"
networks:
- dev
db:
image: mysql
container_name: "db"
restart: always
volumes:
- db-data:/var/lib/mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
networks:
- dev
phpmyadmin:
image: phpmyadmin
container_name: "phpmyadmin"
restart: always
depends_on:
- db
ports:
- 8080:80
environment:
PMA_HOST: db
networks:
- dev
networks:
dev:
volumes:
db-data:
Your Docker Compose file needs to link local folders with Docker folders.
#docker-compose example
version: "3"
services:
web:
build: .
ports:
- "8080:80"
volumes:
- .:/var/www # Map local folder to Docker

How to deal with multiple services inside a docker-compose.yml?

I have been using a Microservices architecture for develop my software, and I have running my services using Docker Compose, but my problem is when the new services were created I have to add them into the docker-compose.yml, and then I got about 200+ hundred lines of code inside the docker-compose.yml, and I have around 17 services for now which the services have related each other.
Then my question is "How to manage the docker-compose.yml to be easy to maintain and clean?"
My docker-compose.yml:
version: '2'
services:
mongo:
container_name: mongodb
image: mongo:3.4.7
volumes:
- ./mongo/data:/data/db
ports:
- 54321:27017
networks:
- zensorium_backend
restart: always
command: mongod --smallfiles
golang_oauth:
container_name: golang_oauth
build: .
volumes:
- ./oauth:/go/src/oauth
working_dir: /go/src/oauth
ports:
- 8080:8082
depends_on:
- mongo
env_file:
- ./.api.env
networks:
- zensorium_backend
command: realize start --run
restart: always
golang_account:
container_name: golang_account
build: .
volumes:
- ./account:/go/src/account
working_dir: /go/src/account
ports:
- 8081:8082
depends_on:
- mongo
env_file:
- ./.api.env
networks:
- zensorium_backend
command: realize start --run
restart: always
golang_client:
container_name: golang_client
build: .
volumes:
- ./client:/go/src/client
working_dir: /go/src/client
ports:
- 8082:8082
depends_on:
- mongo
env_file:
- ./.api.env
networks:
- zensorium_backend
command: realize start --run
restart: always
golang_mail:
container_name: golang_mail
build: .
volumes:
- ./mail:/go/src/mail
working_dir: /go/src/mail
expose:
- 8082
depends_on:
- mongo
env_file:
- ./.api.env
networks:
- zensorium_backend
command: realize start --run
restart: always
golang_user:
container_name: golang_user
build: .
volumes:
- ./user:/go/src/user
working_dir: /go/src/user
ports:
- 8083:8082
depends_on:
- mongo
env_file:
- ./.api.env
networks:
- zensorium_backend
command: realize start --run
restart: always
golang_gateway2:
container_name: golang_gateway2
build: .
volumes:
- ./gateway2:/go/src/gateway
working_dir: /go/src/gateway
ports:
- 8084:8082
depends_on:
- mongo
env_file:
- ./.api.env
networks:
- zensorium_backend
command: realize start --run
restart: always
golang_measurement:
container_name: golang_measurement
build: .
volumes:
- ./measurement:/go/src/measurement
working_dir: /go/src/measurement
ports:
- 8085:8082
depends_on:
- mongo
env_file:
- ./.api.env
networks:
- zensorium_backend
command: realize start --run
restart: always
golang_app:
container_name: golang_app
build: .
volumes:
- ./app:/go/src/app
working_dir: /go/src/app
ports:
- 8086:8082
depends_on:
- mongo
env_file:
- ./.api.env
networks:
- zensorium_backend
command: realize start --run
restart: always
golang_logging:
container_name: golang_logging
build: .
volumes:
- ./logging:/go/src/logging
working_dir: /go/src/logging
ports:
- 8087:8082
networks:
- zensorium_backend
command: realize start --run
restart: always
golang_notify:
container_name: golang_notify
build: .
volumes:
- ./notify:/go/src/notify
working_dir: /go/src/notify
ports:
- 8088:8082
env_file:
- ./.api.env
networks:
- zensorium_backend
command: realize start --run
restart: always
golang_routine:
container_name: golang_routine
build: .
volumes:
- ./routine:/go/src/routine
working_dir: /go/src/routine
ports:
- 8089:8082
env_file:
- ./.api.env
networks:
- zensorium_backend
command: realize start --run
restart: always
angular_cli:
container_name: angular_cli
build: ./angular-cli
ports:
- "4200:4200"
networks:
- zensorium_frontend
working_dir: /home/node/webPortal
volumes:
- ./angular-cli/webPortal:/home/node/webPortal
- /home/node/webPortal/node_modules
restart: always
command: npm start
golang_dev:
container_name: golang_dev
build: .
volumes:
- ./dev:/go/src/dev
working_dir: /go/src/dev
ports:
- 8090:8082
env_file:
- ./.api.env
networks:
- zensorium_backend
command: realize start --run
restart: always
networks:
zensorium_backend:
driver: bridge
zensorium_frontend:
driver: bridge
Also you can use the possibilities of yaml to write repeated strings in shorter way. For example :
---
version: '3.4'
x-command: &command bash -c "ls && sleep infinity"
services:
service1:
command: *command
service2:
command: *command
And man can use templates:
https://matthiasnoback.nl/2018/03/defining-multiple-similar-services-with-docker-compose/
my recommendation is to keep the docker-compose.yml as little as possible if you have a lot of services defined. For example you could write the definition inline, use .env file so you dont always have to specify it, remove the container_name. Moving working_dir to Dockerfile. If you are using version 2, you can use the inheritance of service but this feature is not supported in docker-compose 3 and newer... You should also use named volumes.
example of inline docker-compose.yml
version: '2'
services:
mongo:
image: mongo:3.4.7
command: mongod --smallfiles
restart: always
ports: ["54321:27017"]
networks: [zensorium_backend]
volumes: ["my_mongo_data:/data/db"]
golang_oauth:
build: .
command: realize start --run
restart: always
working_dir: /go/src/oauth # could be moved do Dockerfile
ports: ["8080:8082"]
depends_on: [mongo]
environment: ["VAR_1=${VAR_1}","VAR2=${VAR2}"] # using .env file
networks: [zensorium_backend]
volumes: ["my_oauth_data:/go/src/oauth"]
volumes:
my_mongo_data:
my_oauth_data:
networks:
zensorium_backend:
driver: bridge
zensorium_frontend:
driver: bridge
and .env file in same folder as the .yml
VAR_1=mazel
VAR2=tov

How I can group containers in docker-compose?

I'm using this docker-compose.yml.
And I wanna make simpler and inherrit configuration, if its possible.
version: '2'
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
web_one:
container_name: "web_one"
build:
context: ./
dockerfile: web.docker
volumes:
- ./../one:/var/www
environment:
- VIRTUAL_HOST=whoami_one.local
links:
- app_one
app_one:
container_name: "app_one"
build:
context: ./
dockerfile: app.docker
volumes:
- ./../one:/var/www
links:
- db
web_two:
container_name: "web_two"
build:
context: ./
dockerfile: web.docker
volumes:
- ./../two:/var/www
environment:
- VIRTUAL_HOST=whoami_two.local
links:
- app_two
app_two:
container_name: "app_two"
build:
context: ./
dockerfile: app.docker
volumes:
- ./../two:/var/www
links:
- db
I have 15 sites with same configuration.
Can I make config simpler? Like this:
version: '2'
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
one:
extends:
file: common-services.yml
volumes:
- ./../one:/var/www
environment:
- VIRTUAL_HOST=whoami_one.local
two:
extends:
file: common-services.yml
volumes:
- ./../two:/var/www
environment:
- VIRTUAL_HOST=whoami_two.local
Or better?
Thank you!
UPDATE 31 Aug 2021 In the latest docker compose there's support for profiles https://docs.docker.com/compose/profiles/ so this problem would be perfectly solved by that new feature.
Another way is to create no-op services that depend on other services.
For example, in the following docker-compose.yml I have two namespaces, dev for services needed when developing the app, and metrics for services related to visualizing app metrics (since I'm not interested instarting those when developing).
version: "3"
services:
dev:
image: tianon/true
depends_on: ["postgres", "keycloak"]
metrics:
image: monroe/noop
depends_on: ["grafana"]
postgres: ...
keycloak: ...
grafana: ...

Resources