Can't run the docker compose file - docker

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:

Related

YAML error while using Docker-Composure command

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

Gitlab CI shell runner fails with docker-compose up

I'm trying to start multiple docker containers with a wsl shell runner. After running
compose_job:
tags:
- wsl
stage: compose
script:
- cd /pathToComposeFile
- docker-compose up
dependencies:
- pull_job
the runner excited with following error:
$ docker-compose up
docker: invalid reference format: repository name must be lowercase.
the docker-compose.yml is:
version: '3'
services:
cron:
build: cron/.
container_name: cron
image: cron_image
ports:
- 6040:6040
The referenced images are all written in lowercase and the same command excited as expected
if run manually. I already checked that docker-compose is accessible and that the docker-compose.yml is readable. How can I resolve this issue? Thank you in advance!
I think service_name, container_name and env must be lowercase.
Look like
version: '3'
services:
perihubapi:
build:
context: api/.
args:
EXTERNAL: ${external}
FASERVICES: ${faservices}
container_name: perihubapi
image: peri_hub_api_image
ports:
- 6020:6020
networks:
- backend
volumes:
- peridigm_volume:/app/peridigmJobs
- paraView_volume:/app/paraView
- secrets:/app/certs
perihubgui:
build: gui/.
container_name: perihubgui
image: peri_hub_gui_image
ports:
- 6010:6010
networks:
- backend
volumes:
- secrets:/app/certs
peridigm:
build:
context: peridigm/.
args:
GITLAB_USER: ${gitlab_user}
GITLAB_TOKEN: ${gitlab_token}
PERIDOX: ${peridox}
container_name: peridigm
image: peridigm_image
ports:
- 6030:6030
networks:
- backend
volumes:
- peridigm_volume:/app/peridigmJobs
paraview:
build:
context: paraview/.
container_name: paraview
image: paraview_image
volumes:
- paraView_volume:/app/paraView
cron:
build: cron/.
container_name: cron
image: cron_image
ports:
- 6040:6040
networks:
- backend
networks:
backend:
driver: bridge
volumes:
peridigm_volume:
paraView_volume:
secrets:
external: true

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 yaml.parser.ParserError

With the following docker-compose.yml I always get a syntax error I can't explain (I don't see the difference in lines 2 and 3 between the two docker-compose.ymls)
---
version: '2'
services:
app-module:
container_name: app-module:
env_file: ./app-module:.env
image: registry.x/app/app-module:latest
network_mode: "bridge"
ports:
- "30303:30303"
volumes:
- type: volume
source: node-volume
target: /datadir
- ./data:/data
- ./log:/log
Error message:
ERROR: yaml.parser.ParserError: while parsing a block mapping
in "./docker-compose.yml", line 2, column 1
expected <block end>, but found '<block mapping start>'
in "./docker-compose.yml", line 3, column 3
I don't see any syntax differences to other working files.
That's the working docker-compose.yml I used as the inspiration of my file:
---
version: '2'
services:
app-node:
container_name: app-node
env_file: ./app-node.env
image: registry.x/group/app-node:latest
network_mode: "bridge"
ports:
- "7990:7990"
- "7999:7999"
volumes:
- ./data:/data
- ./log:/log
Proof:
$ docker-compose config
services:
app-node:
container_name: app-node
environment: {}
image: registry.x/group/app-node:latest
network_mode: bridge
ports:
- 7990:7990/tcp
- 7999:7999/tcp
volumes:
- ...app-node/Test/data:/data:rw
- ...app-node/Test/log:/log:rw
version: '2.0'
Spaces matter in YAML. You have two spaces before services: that are not supposed to be there. You're telling YAML that services is in version but version already has a value.
It's the difference between:
foo: bar
in_foo: bar
which will not work because in_foo is in foo, and:
foo: bar
not_in_foo: bar
that will work because not_in_bar is not in foo.
Alternatively, this would be valid syntax (but then docker-compose will fail because it expects a string in version):
version:
services:
foo: bar

After executing docker-compose command geting error yaml.scanner.ScannerError

Docker compose file:
version: '2'
services:
wordpress:
image: wordpress
ports:
-8080:80
environment:
WORDPRESS_DB_PASSWORD:vvk123
mysql:
image:mysql:latest
environment:
MYSQL_ROOT_PASSWORD:vvk123
when i was tring to execute this command
docker-compose ps
its giving error called
yaml.scanner.ScannerError: mapping values are not allowed here in
".\docker-compose.yml", line 12, column 20
Try adding a space after the column in line 12:
version: '2'
services:
wordpress:
image: wordpress
ports:
- 8080:80
environment:
- WORDPRESS_DB_PASSWORD:vvk123
mysql:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD:vvk123

Resources