YAML error while using Docker-Composure command - docker

I am a newbie in the docker world and while doing some tutorials I encountered the following error:
yaml: line 1: did not find expected key
This is my .YAML file:
version: '3'
services:
mongodb:
image: mongo
ports:
-27017:27017
environment:
- MONGO-INITDB_ROOT_USERNAME=admin
- MONGO-INITDB_ROOT_PASSWORD=password
mongo-express:
image: mongo-express
ports:
-8080:8081
environment:
-ME_CONFIG_MONGODB_ADMINUSERNAME=admin
-ME_CONFIG_MONGODB_ADMINPASSWORD=password
-ME_CONFIG_MONGODB_SERVER=mongodb
I tried to search if there is a problem with the compatibility of the docker-compose & docker-engine but even though I tried to put other versions like 2/2.1/2.2/2.3/3/3.8 in the ".YAML" file I still get the same error message.
Docker Compose version v2.2.1 <br>
Docker Engine v20.10.11
Tried to look up some solutions but I was not able to find anything.

Your indentation is incorrect and some other spacing/syntax is also incorrect.
version: '3'
services:
mongodb:
image: mongo
ports:
- 27017:27017
environment:
- MONGO-INITDB_ROOT_USERNAME=admin
- MONGO-INITDB_ROOT_PASSWORD=password
mongo-express:
image: mongo-express
ports:
- 8080:8081
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
- ME_CONFIG_MONGODB_ADMINPASSWORD=password
- ME_CONFIG_MONGODB_SERVER=mongodb

Related

Invalid docker.compose.yaml file

I am trying to get a couple of containers up and running, however I am running into some issues. I run this command:
docker-compose up -d --build itvdflab
and get this error
The Compose file './docker-compose.yaml' is invalid because:
Unsupported config option for services: 'itvdelab'
Unsupported config option for networks: 'itvdelabnw'
Here is the yaml file.
services:
itvdelab:
image: itversity/itvdelab
hostname: itvdelab
ports:
- "8888:8888"
volumes:
- "./itversity-material:/home/itversity/itversity-material"
- "./data:/data"
environment:
SHELL: /bin/bash
networks:
- itvdelabnw
depends_on:
- "cluster_util_db"
cluster_util_db:
image: postgres:13
ports:
- "6432:5432"
volumes:
- ./cluster_util_db_scripts:/docker-entrypoint-initdb.d
networks:
- itvdelabnw
environment:
POSTGRES_PASSWORD: itversity
itvdflab:
build:
context: .
dockerfile: images/pythonsql/Dockerfile
hostname: itvdflab
ports:
- "8888:8888"
volumes:
- "./itversity-material:/home/itversity/itversity-material"
- "./data:/data"
environment:
SHELL: /bin/bash
networks:
- itvdelabnw
depends_on:
- "pg.itversity.com"
pg.itversity.com:
image: postgres:13
ports:
- "5432:5432"
networks:
- itvdelabnw
environment:
POSTGRES_PASSWORD: itversity
networks:
itvdelabnw:
name: itvdelabnw
What changes do I need to make to get this working?
Your docker-compose.yml file is missing a version: line. Until very recently, this caused Docker Compose to interpret this as the original "version 1" Compose format, which doesn't have a top-level services: key and doesn't support Docker networks. The much newer Compose Specification claims that a version: key is optional, but in practice if you can't be guaranteed to use a very new version of Compose (built as a plugin to the docker binary) it's required. The most recent Compose file versions supported by the standalone Python docker-compose tool are 3.8 and 2.4 (you need the 2.x version for some resource-related constraints in non-Swarm installations).
# Add at the very beginning
version: '3.8'
Here is the revised copy:
version: '3.4'
services:
itvdelab:
image: itversity/itvdelab
hostname: itvdelab
ports:
- "8888:8888"
volumes:
- "./itversity-material:/home/itversity/itversity-material"
- "./data:/data"
environment:
SHELL: /bin/bash
networks:
- itvdelabnw
depends_on:
- "cluster_util_db"
cluster_util_db:
image: postgres:13
ports:
- "6432:5432"
volumes:
- ./cluster_util_db_scripts:/docker-entrypoint-initdb.d
networks:
- itvdelabnw
environment:
POSTGRES_PASSWORD: itversity
itvdflab:
build:
context: .
dockerfile: images/pythonsql/Dockerfile
hostname: itvdflab
ports:
- "8888:8888"
volumes:
- "./itversity-material:/home/itversity/itversity-material"
- "./data:/data"
environment:
SHELL: /bin/bash
networks:
- itvdelabnw
depends_on:
- "pg.itversity.com"
pg.itversity.com:
image: postgres:13
ports:
- "5432:5432"
networks:
- itvdelabnw
environment:
POSTGRES_PASSWORD: itversity
networks:
itvdelabnw:
name: itvdelabnw
and now I get the following error
ERROR: The Compose file './docker-compose.yaml' is invalid because:
services.pg.itversity.com.networks.itvdelabnw contains unsupported option: 'name'
for me work try different version. In my case work
version: '2.2'

Can't run the docker compose file

Can somebody, please, help me to understand what's wrong with my docker-compose.yml file?
version: '3'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins
ports:
- "8080:8080"
volumes:
- "$PWD/jenkins_home:/var/jenkins_home"
networks:
- net
networks:
net:
I get an error:
ERROR: yaml.parser.ParserError: while parsing a block mapping
in "./docker-compose.yml", line 1, column 1
expected <block end>, but found '<block mapping start>'
in "./docker-compose.yml", line 2, column 3
Try the following. There seem to be multiple issues with your compose file.
version: '3'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins
ports:
- "8080:8080"
volumes:
- "$PWD/jenkins_home:/var/jenkins_home"
Note: If the following doesn't work, share the full docker-compose.yaml and the Docker compose version.
You should indent lines after services, so the correct form is:
version: '3'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins
ports:
- "8080:8080"
volumes:
- "$PWD/jenkins_home:/var/jenkins_home"
networks:
- net
networks:
net:

The Compose filedocker-compose.yml' is invalid because environment contains an invalid type, it should be an object, or an array

I found this docker compose container on an asian site, and was trying to run it, and then I got the following. I had to modify the docker compose file because there were duplicated characters. I'm not sure why this won't run, and i have looked on stackoverflow for other issues, but none resolved my issue.
The docker compose file is as follows:
---
version: '3.5'
services:
wowonder-web:
container_name: wowonder-web
image: webdevops/php-apache:debian-10
environment:
-WEB_DOCUMENT_ROOT=/app
-PHP_MEMORY_LIMIT=1024M
-PHP_MAX_EXECUTION_TIME=7200
-PHP_POST_MAX_SIZE=10240M
-PHP_UPLOAD_MAX_FILESIZE=10240M
-FPM_MAX_REQUESTS=500
-FPM_PM_MAX_CHILDREN=20
-FPM_PM_START_SERVERS=10
-FPM_PM_MIN_SPARE_SERVERS=5
-FPM_PM_MAX_SPARE_SERVERS=15
volumes:
- /opt/wowonder/app:/appwowonder:/app
restart: unless-stopped
wowonder-db:
container_name: wowonder-db
image: mariadb
environment:
-MYSQL_ROOT_PASSWORD="wowonder"
-MYSQL_PASSWORD="wowonder"
-MYSQL_DATABASE="wowonder"
-MYSQL_USER="wowonder"
volumes:
- /docker/Databases/wowonder:/var/lib/mysqldb
command: --sql-mode="NO_ENGINE_SUBSTITUTION"
restart: unless-stopped
networks:
default:
external:
name: imlala
A few mistypes (check this online YAML validator in the future):
First, as #DavidMaze noted, to create a YAML array in a docker-compose file the most popular option is to create a new line for each element and start with a hyphen and a space right after it, you can browse other options in this SO thread
environment:
- WEB_DOCUMENT_ROOT=/app
- PHP_MEMORY_LIMIT=1024M
- PHP_MAX_EXECUTION_TIME=7200
- PHP_POST_MAX_SIZE=10240M
- PHP_UPLOAD_MAX_FILESIZE=10240M
- FPM_MAX_REQUESTS=500
- FPM_PM_MAX_CHILDREN=20
- FPM_PM_START_SERVERS=10
- FPM_PM_MIN_SPARE_SERVERS=5
- FPM_PM_MAX_SPARE_SERVERS=15
Second, your command for wowonder-db was too much indented, taking it a step back fixed the issue.
volumes:
- /docker/Databases/wowonder:/var/lib/mysqldb
command: --sql-mode="NO_ENGINE_SUBSTITUTION"
restart: unless-stopped
Complete and valid compose file:
---
version: '3.5'
services:
wowonder-web:
container_name: wowonder-web
image: webdevops/php-apache:debian-10
environment:
- WEB_DOCUMENT_ROOT=/app
- PHP_MEMORY_LIMIT=1024M
- PHP_MAX_EXECUTION_TIME=7200
- PHP_POST_MAX_SIZE=10240M
- PHP_UPLOAD_MAX_FILESIZE=10240M
- FPM_MAX_REQUESTS=500
- FPM_PM_MAX_CHILDREN=20
- FPM_PM_START_SERVERS=10
- FPM_PM_MIN_SPARE_SERVERS=5
- FPM_PM_MAX_SPARE_SERVERS=15
volumes:
- /opt/wowonder/app:/appwowonder:/app
restart: unless-stopped
wowonder-db:
container_name: wowonder-db
image: mariadb
environment:
- MYSQL_ROOT_PASSWORD="wowonder"
- MYSQL_PASSWORD="wowonder"
- MYSQL_DATABASE="wowonder"
- MYSQL_USER="wowonder"
volumes:
- /docker/Databases/wowonder:/var/lib/mysqldb
command: --sql-mode="NO_ENGINE_SUBSTITUTION"
restart: unless-stopped
networks:
default:
external:
name: imlala

Docker compose Unsupported config option for service volume mongodb

I am trying to learn docker by reading the official documentation. I am on the task of Use Compose to develop locally. Trying to compose mongodb but I got an error
The Compose file './docker-compose.dev.yml' is invalid because:
Unsupported config option for services.volumes: 'mongodb'
here is docker-compose.dev.yml file:
version: '3.8'
services:
notes:
build:
context: .
ports:
- 8080:8080
- 9229:9229
environment:
- SERVER_PORT=8080
- DATABASE_CONNECTIONSTRING=mongodb://mongo:27017/notes
volumes:
- ./:/code
command: npm run debug
mongo:
image: mongo:4.2.8
ports:
- 27017:27017
volumes:
- mongodb:/data/db
- mongodb_config:/data/configdb
volumes:
mongodb:
mongodb_config:
How can I make it work?
That's a small mistake on your part, the volumes section of the docker-compose.yaml file is related to all services and not one in particular, because of how yaml files are formatted the indentation level matters a lot, in your example you didn't use the volumes parameter, instead you defined a service called volumes and services don't have a parameter called mongodb.
You have to simply decrease the identation level on the last 3 lines and it will work just fine.
version: '3.8'
services:
mongo:
image: mongo:4.2.8
ports:
- 27017:27017
volumes:
- mongodb:/data/db
- mongodb_config:/data/configdb
volumes:
mongodb:
mongodb_config:

docker-compose couchdb missing files

I'm trying to run couchdb via docker-compose:
version: '3'
services:
couchdb:
image: "couchdb:2"
restart: always
ports:
- 5984:5984
volumes:
- /data/couchdb:/opt/couchdb/etc/
- /data/couchdb_config:/opt/couchdb/etc/local.d
environment:
- COUCHDB_USER=myuser
- COUCHDB_PASSWORD=mypassword
the container crashes during start:
Failed to open arguments file "/opt/couchdb/bin/../etc/vm.args": No such file or directory
Usage: erl......
grep: /opt/couchdb/etc/default.d/*.ini: No such file or directory
In data/couchdb_config I am providing a standard local.ini file. When I don't do that, couchdb complains that it's missing as well.
What's the problem here?
you need to set points before data path .Docker-comose need to know that data is in the same path as the docker-compose file
version: '3'
services:
couchdb:
image: "couchdb:2"
restart: always
ports:
- 5984:5984
volumes:
- ./data/couchdb:/opt/couchdb/etc/
- ./data/couchdb_config:/opt/couchdb/etc/local.d
environment:
- COUCHDB_USER=myuser
- COUCHDB_PASSWORD=mypassword
The error was the mapping of a wrong volume:
my_couchdb_data:/opt/couchdb/etc
should be
my_couchdb_data:/opt/couchdb/data

Resources