Reputation: 29
I am trying to run docker-compose but facing the below error. Can someone help?
version: '3.2'
services:
elasticsearch:
build:
context: elasticsearch/
args:
ELK_VERSION: $ELK_VERSION
volumes:
- type: bind
source: ./elasticsearch/config/elasticsearch.yml
target: /usr/share/elasticsearch/config/elasticsearch.yml
read_only: true
- type: bind
source: elasticsearch
target: /usr/share/elasticsearch/data
ports:
- "9200:9200"
- "9300:9300"
environment:
ES_JAVA_OPTS: "-Xmx256m -Xms256m"
# ELASTIC_PASSWORD: changeme
discovery.type: single-node
networks:
- elg
logstash:
build:
context: logstash/
args:
ELK_VERSION: $ELK_VERSION
volumes:
- type: bind
source: ./logstash/config/logstash.yml
target: /usr/share/logstash/config/logstash.yml
read_only: true
- type: bind
source: ./logstash/pipeline/
target: /usr/share/logstash/pipeline/
- type: bind
source: ./data/
target: /usr/share/logstash/data
ports:
- "5044:5044"
- "5000:5000/tcp"
- "5000:5000/udp"
- "9600:9600"
#command: --config.reload.automatic
environment:
LS_JAVA_OPTS: "-Xmx256m -Xms256m"
networks:
- elg
depends_on:
- elasticsearch
grafana:
container_name: grafana
image: grafana/grafana
environment:
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
ports:
- 3000:3000
depends_on:
- elasticsearch
networks:
- elg
depends_on:
- elasticsearch
networks:
elg:
driver: bridge
volumes:
elasticsearch:
mysql_db_container:
container_name: mysql
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: rootpassword
volumes:
type: bind
source: ./home/practical-devsecops/docker-elg/my-db
target: /var/lib/mysql
ports: "3306:3306"
networks:
elg:
driver: bridge
adminer_container:
container_name: adminer
image: adminer:latest
environment:
ADMINER_DEFAULT_SERVER: mysql_db_container
ports: "8080:8080"
networks:
elg:
driver: bridge
volumes.adminer value Additional properties are not allowed ('environment', 'image', 'ports', 'container_name' were unexpected) volumes.mysql value Additional properties are not allowed ('target', 'image', 'environment', 'source', 'command', 'volumes', 'container_name', 'type', 'ports' were unexpected)
Upvotes: 2
Views: 20590
Reputation: 159382
Your docker-compose.yml
file is mixing top-level blocks together. Abstracting away all of the content, you have:
version: '3.2'
services:
elasticsearch: { a: service definition }
logstash: { a: service definition }
grafana: { a: service definition }
networks:
elg: { a: network definition }
volumes:
elasticsearch: # null
mysql_db_container: { a: service definition } # <----
networks:
elg: { a: network definition }
adminer_container: { a: service definition } # <----
networks:
elg: { a: network definition }
Notice that mysql_db_container
is under volumes:
, and adminer_container
is under networks:
. Compose ignores that they have a Compose service layout and the word "container" in their name, and tries to interpret them according to the top-level block they're under.
You should be able to restructure this to have services:
, networks:
, and volumes:
at the top level once only:
version: '3.8'
services:
elasticsearch: { a: service definition }
logstash: { a: service definition }
grafana: { a: service definition }
mysql_db_container: { a: service definition } # <----
adminer_container: { a: service definition } # <----
networks:
elg: { a: network definition }
volumes:
elasticsearch: # null
(You can also safely remove networks:
everywhere in the file. Compose will create a network named default
with default settings and attach the various containers to it. You also shouldn't usually need container_name:
in routine use. There are a couple of duplicated depends_on:
blocks as well and you can clean these up, but I don't think they'll cause problems.)
Upvotes: 1
Reputation: 12887
The issue you have is with the indentation around the mysql_db_container service The lines:
networks:
elg:
driver: bridge
volumes:
elasticsearch:
in between your grafana and mysql_db_container service specification is indented incorrectly. As it at present, they break the service specification and cause docker-compose to complain.
Upvotes: 4