How to enable DNS Load Balancing in a Docker Compose YAML file? - docker

I have a simple docker-compose.yaml file with 2 ElasticSearch services:
version: '3'
services:
elasticsearch1:
image: elasticsearch:6.5.4
restart: always
elasticsearch2:
image: elasticsearch:6.5.4
restart: always
I want to enable DNS Load Balancing for them in the compose file, but I did not find a way to do this. I know that with docker run this is possible using --net-alias. What's the equivalent in Docker Compose?

The same functionality is there in a compose file:
version: '3'
services:
elasticsearch1:
image: elasticsearch:6.5.4
restart: always
networks:
default:
aliases:
- elasticsearch
elasticsearch2:
image: elasticsearch:6.5.4
restart: always
networks:
default:
aliases:
- elasticsearch
https://docs.docker.com/compose/compose-file/#aliases

Related

Docker compose application has not public ports on digitalocean

I have docker compose web app:
version: '3.3'
services:
app:
image: xxxxxxxxxxxxx
restart: always
network_mode: 'host'
image is hidden because of private code
After startup I can call wget http://localhost:4004 on server but once I call PUBLICIP:4004 it doesnt wor, looks like port is not accesable. Firawall is disabled. I am using ubuntu.
Is there any wrong with docker compose?
I tried to google and SO
If you want to publish only port add ports key:
version: '3.3'
services:
app:
image: xxxxxxxxxxxxx
ports:
- "4004:4004"
You can read more here:
https://docs.docker.com/compose/networking/
Probably you will be interested in connecting it to domain and securing by ssl. I recommend you check nginx-proxy-automation.
https://github.com/evertramos/nginx-proxy-automation
I appending below example from my production that works with this library
version: '3'
services:
gql:
image: registry.digitalocean.com/main/xue-gql
ports:
- ${DOCKER_PORT}:4000
env_file:
- .env
environment:
- VIRTUAL_HOST=${HOST}
- LETSENCRYPT_HOST=${HOST}
- VIRTUAL_PORT=${DOCKER_PORT}
command: node ./src/index.js
redis:
image: 'redis:alpine'
networks:
default:
external:
name: ${NETWORK:-proxy}

Converting a docker-compose.yml file with Kompose to K8S with a build step

I've the following docker-compose.yml file, I'd like to convert it to K8S configuration files.
version: '3.1'
services:
api-fiber:
build:
context: .
dockerfile: Dockerfile
ports:
- 8666:8666
volumes:
- ./:/var/app/current
networks:
- api-network
redis:
image: redis:latest
container_name: redis
restart: always
ports:
- 6379:6379
networks:
api-network:
driver: bridge
Kompose converts the resources to yaml, but skip the build section of the api-fiber specs. How to reference this step to make Kompose aware of it?

Need to up my docker file in ubuntu "docker-compose up -d"

services:
postgres:
container_name: 'lh-postgres'
image: 'postgres:13'
environment:
POSTGRES_PASSWORD: root
redis:
container_name: 'lh-redis'
image: 'redis:6'
nginx:
container_name: 'lh-nginx'
build: ./nginx
depends_on:
- php-fpm
volumes:
- ./src/lh-app:/var/www/html/app
- ./src/lh-api:/var/www/html/api
ports:
- "80:80"
- "443:443"
php-fpm:
container_name: 'lh-php'
image: docker.io/bitnami/php-fpm:8.0
user: '1000:1000'
build:
context: ./php-fpm
args:
- PHP_ENV= development
depends_on:
- postgres
- redis
volumes:
- ./src/lh-app:/var/www/html/app
- ./src/lh-api:/var/www/html/api
ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services: 'postgres'
getting this error
I think you are missing some ENV vars.
This is our docker-compose.yml for Postgres
version: '3.9'
services:
db:
image: postgres:latest
restart: "no"
container_name: db
volumes:
- ./database:/var/lib/postgresql/data
ports:
- "8002:5432"
environment:
POSTGRES_PASSWORD: verySecurePassword34058
POSTGRES_USER: root
POSTGRES_DB: myDatabase
networks:
default:
external: true
name: our-network
Other parts of the application, (like Redis, the NodeJS App, etc) are in other docker-compose.yml files, But since they share the same network, they talk to each other.
You have not mentioned version in docker-composer.yml
version: '2'
services:
postgres:
container_name: 'lh-postgres'
image: 'postgres:13'
environment:
POSTGRES_PASSWORD: root
redis:
container_name: 'lh-redis'
image: 'redis:6'
You should include your docker and docker-compose version in the querstion to help us answer you.
It would also be wise to define the version: 'x' element at the top of your compose file.
You may be suffering from an old version of the cli, akin to this question:
docker-compose : Unsupported config option for services service: 'web'

Unsupported config option for services.networks: 'my_network'

I am having below error while running the docker-compose file.
I have created a bridge network with name my_network
Unsupported config option for services.networks: 'my_network'
docker-compose.yml
version: '3.3'
services:
webapp1:
image: nginx:latest
container_name: my_container
ports:
- "8080:8080"
networks:
- my_network
volumes:
- /home/ajay/nginx:/www/data
That seems docker-compose configuration issue, use below docker-compose file, it will create a network and then you can use the same network in the docker-compose file.
version: '3.5'
services:
webapp1:
image: nginx:latest
container_name: my_container
ports:
- "8080:80"
networks:
- my_network
networks:
my_network:
driver: bridge
Also Nginx port should be 80 inside the container if you did not modify the default configuration.

docker compose issue on windows 10

I have an opensource project cloned, and it has docker-compose.yml.
I execute
docker-compose up
But I see error:
ERROR: could not find plugin bridge in v1 plugin registry: plugin not found
I even tried a commonly mentioned solution on SO:
docker network create --driver nat network-name
But issue still persists.
I understand that docker-compose is part of docker desktop install on windows.
How to solve it?
Content of the file:
version: "3"
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.7.0
ports: ["9200:9200"]
networks: ["sandbox"]
environment: ["discovery.type=single-node"]
kibana:
image: docker.elastic.co/kibana/kibana:6.7.0
ports: ["5601:5601"]
networks: ["sandbox"]
depends_on: ["elasticsearch"]
logstash:
image: docker.elastic.co/logstash/logstash:6.7.0
volumes:
- ./config/logstash.conf:/usr/share/logstash/pipeline/logstash.conf
networks: ["sandbox"]
ports: ["5000:5000/udp"]
depends_on: ["elasticsearch"]
grafana:
image: grafana/grafana:6.0.2
volumes: ["./grafana/plugins/cinnamon-elasticsearch-app:/var/lib/grafana/plugins/cinnamon-elasticsearch-app"]
ports: ["3000:3000"]
networks: ["sandbox"]
depends_on: ["elasticsearch"]
networks:
sandbox:
driver: bridge

Resources