ERROR: yaml.scanner.ScannerError: while scanning a simple key - docker-compose

I get the following error from docker-compose:
docker-compose up -d
ERROR: yaml.scanner.ScannerError: while scanning a simple key
in "./docker-compose.yml", line 4, column 1
could not find expected ':'
in "./docker-compose.yml", line 5, column 1
This is my docker-compose.yaml:
version: '2.0'
services:
  #PHP Service
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: cloudsigma.com/php
    container_name: app
    restart: unless-stopped
    tty: true
    environment:
      SERVICE_NAME: app
      SERVICE_TAGS: dev
    working_dir: /var/www/html/
    volumes:
      - ./:/var/www/html/
      - ./php/laravel.ini:/usr/local/etc/php/conf.d/laravel.ini
    networks:
      - app-network
Can somebody tell me what is wrong with my compose file?

Seems Like you have copied yml file from any other editor ( Like, if you share the compose file using Slack, you get this error )
Solution: Copy your code and past it to some online yml validator (https://codebeautify.org/yaml-validator) and you will
find some red dots extra. Remove those and your are done.
I hope this helps someone still facing this situation

Related

ERROR: In file './docker-compose.yml', service 'container_name' must be a mapping not a string

When I ran: docker-compose up -d, I got error saying
"ERROR: In file './docker-compose.yml', service 'container_name' must be a mapping not a string."
This is my yml file:
version'3' services:
web:
container_name: nginx1
ports:
- "8080:80"
image: nginx
~
Version is property, also whitespaces has meaning in yaml:
version: '3'
services:
web:
container_name: nginx1
...

docker-compose Couldn't find env file: path\variables.env

This is my first time using environment variables in docker-compose.
When I run the docker-compose up command I get the error:
docker-compose Couldn't find env file: ${path}\variables.env
Hereinafter "path" is the path to the project in Windows.
Here is my docker-compose.yml:
version: '3.1'
services:
geo:
build:
context: .
image:geo_image
container_name: geo
ports:
- "3003:3003"
volumes:
- ${path}:/var/geo/data
- /app/node_modules
- ${path}:/app
env_file: variables.env
networks:
default:
external:
name: geonw
The variables.env file is located at the root of the project.
Without variables.env everything works fine.
Tell me, please, what is the error?
I tried giving the full path to the file, but that didn't work either.
I also carefully checked the correct name of the file variables.env, there is no error there.
I'm sorry, but it was just my stupid mistake and inattention. I created a variables.env file at a level higher than the directory with the docker-compose.yml file.
2 hours wasted...
Answer: The variables.env and docker-compose.yml files must be in the same directory.
Try this should work.. also try with \ slash .\variables.env
version: '3.1'
services:
geo:
build:
context: .
image:geo_image
container_name: geo
ports:
- "3003:3003"
volumes:
- ${path}:/var/geo/data
- /app/node_modules
- ${path}:/app
env_file:
- ./variables.env
networks:
default:
external:
name: geonw

material-ui-docs site won't run Error: Cannot find module 'babel-plugin-macros'

no issues section available at GitHub material-ui-docs :(, so I try to ask here.
BTW seems weird to install outside container :/
when tried to install, got error:
error - ./pages/_app.js
mui-docs | Error: Cannot find module 'babel-plugin-macros'
mui-docs | Require stack:
mui-docs | - /home/node/material-ui-docs/node_modules/next/dist/compiled/babel/bundle.js
mui-docs | - /home/node/material-ui-docs/node_modules/next/dist/compiled/babel/code-frame.js
mui-docs | - /home/node/material-ui-docs/node_modules/next/dist/build/webpack/plugins/wellknown-errors-plugin/parseScss.js
here is docker-compose.yml
version: "3.5"
services:
svcMuiDocs:
image: "node:17-slim"
restart: always
container_name: "mui-docs"
#user: "node"
working_dir: /home/node/material-ui-docs
environment:
- NODE_ENV=production
volumes:
- "./:/home/node/material-ui-docs:rw"
ports:
- "8012:8012"
entrypoint: ["/bin/sh","-c"]
command:
- |
yarn && yarn docs:dev --port=8012
networks:
- default
networks:
default:
external:
name: svcBackend
site won't start
can anybody help please ?
AS.
well, just blind shooting... replaced few words in docker-compose.yml to:
version: "3.5"
services:
svcMuiDocs:
image: "node:17-slim"
restart: always
container_name: "mui-docs"
#user: "node"
working_dir: /home/node/material-ui-docs
environment:
- NODE_ENV=development
volumes:
- "./:/home/node/material-ui-docs:rw"
ports:
- "8012:8012"
entrypoint: ["/bin/sh","-c"]
command:
- |
yarn --ignore-platform && yarn docs:dev --port=8012
networks:
- default
networks:
default:
external:
name: svcBackend
NODE_ENV=development
added --ignore-platform to yarn
and viola it works :)
AS.

How to specify multiple "env_files" for a docker compose service?

Currently I have setup my service like the following.
version: '3'
services:
gateway:
container_name: gateway
image: node:lts-alpine
working_dir: /
volumes:
- ./package.json:/package.json
- ./tsconfig.json:/tsconfig.json
- ./services/gateway:/services/gateway
- ./packages:/packages
- ./node_modules:/node_modules
env_file: .env
command: yarn run ts-node-dev services/gateway --colors
ports:
- 3000:3000
So I have specified one env_file. But now I want to pass multiple .env files.
Unfortunately, the following is not possible:
env_files:
- .env.secrets
- .env.development
Is there any way to pass multiple .env files to one service in docker-compsoe?
You can specify multiple env files on the env_file option (without s).
For instance:
version: '3'
services:
hello:
image: alpine
entrypoint: ["sh"]
command: ["-c", "env"]
env_file:
- a.env
- b.env
Note that, complementary to #conradkleineespel's answer, if an environment variable is defined in multiple .env files listed under env_file, the value found in the last environment file in the list overwrites all prior (tested in a docker-compose file with version: '3.7'.

Docker compose MySQL-volumes invalid invalid specification

I am using service 3 and below is mycode,
I tried to add the var- COMPOSE_CONVERT_WINDOWS_PATHS: 1 in environment
it still get the error:
ERROR: for db-on-docker-ms_mysql-dev_1 Cannot create container for service mysql-dev: invalid volume specification: '/c/Dockerfile/db-on-docker-ms:/var/lib/mysql under volumes:rw'
version: '3'
services:
mysql-dev:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: blogapp
ports:
- "3308:3306"
volumes:
- /c/Dockerfile/db-on-docker-ms:/var/lib/mysql
My Docker Version: 18.09.2
I think you either need set COMPOSE_CONVERT_WINDOWS_PATHS environment variable from your command line
$ export COMPOSE_CONVERT_WINDOWS_PATHS=1
Then change the volumes configuration
version: '3'
services:
mysql-dev:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: blogapp
ports:
- "3308:3306"
volumes:
- c:\Dockerfile\db-on-docker-ms:/var/lib/mysql
Run docker compose
$ docker-compose up
Or you can attempt to set the volumes like this
version: '3'
services:
mysql-dev:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: blogapp
ports:
- "3308:3306"
volumes:
- //c/Dockerfile/db-on-docker-ms:/var/lib/mysql
And run docker compose
$ docker-compose up
Thanks for Misantorp's ans first!
I finally figure out how to do it in windows container
the volumes path should be:
volumes:
- C:\Dockerfile\db-on-docker-ms:/var/lib/mysql
run the command in powershell:
COMPOSE_CONVERT_WINDOWS_PATHS=0
then run:
docker-compose up