Why this is not working on docker compose version 3?
nginx:
image: nginx
container_name: nginx
environment:
VIRTUAL_HOST: >
proj1.local,proj2.local,
proj3.local,proj4.local,proj5.local
I've a lot of virtual hosts and I need to go multilne but I receive:
ERROR: yaml.scanner.ScannerError: while scanning a simple key
in "./docker-compose.yml", line 31, column 7
could not find expected ':'
in "./docker-compose.yml", line 32, column 7
What am I doing wrong?
Tools such as Yamllint are your friend when seeing those types of errors. That said, it sometimes doesn't give you a meaningful error when failing validation.
What you have in the example is an indentation problem. You should be using:
nginx:
image: nginx
container_name: nginx
environment:
VIRTUAL_HOST: >
proj1.local,proj2.local,
proj3.local,proj4.local,proj5.local
Which will translate into:
nginx:
container_name: nginx
environment:
VIRTUAL_HOST: "proj1.local,proj2.local, proj3.local,proj4.local,proj5.local"
image: nginx
Related
I'm new to Docker and I'm following a tutorial that was made for Linux (I'm using Windows). I am trying to change a ./script.sh command with one that uses a PowerShell script. &script.ps1 does not work. Here is the code:
version: "3.8"
services:
frontend:
depends_on:
- backend
build: ./frontend
ports:
- 3000:3000
backend:
depends_on:
- db
build: ./backend
ports:
- 3001:3001
environment:
DB_URL: mongodb://db/vidly
volumes:
- ./backend:/app
command: &script.ps1 # instead of ./script.sh
db:
image: mongo:4.0-xenial
ports:
- 27017:27017
volumes:
- vidly:/data/db
volumes:
vidly:
the error I receive is
in ".\docker-compose.yml", line 22, column 14
expected alphabetic or numeric character, but found '"' in ".\docker-compose.yml", line 22, column 15
in ".\docker-compose.yml", line 22, column 14 expected alphabetic or numeric character, but found '"' in ".\docker-compose.yml", line 22, column 15
Every docker-compose.yaml first need to be a valid yaml file, you could use docker-compose config to verify it. Here, what you need to is wrap &script.ps1 with double quotation mark to make it be valid yaml:
command: "&script.ps1"
I have a similar issue but the suggested answer does not seems to work for me. My problem is that I want to split an app on multiple containers. One of the components is willing to connect to a local redis (which I have now moved in its own container)
version: '3'
services:
server-test:
image: redis:alpine
command: redis-cli -h redis-db ping
redis-db:
image: redis
expose:
- "6379"
works fine - but I want something along this line:
version: '3'
services:
server-test:
image: redis:alpine
command: redis-cli ping
redis-db:
image: redis
expose:
- "6379"
I have tried to add the lines:
ports:
- "6379:redis-db:6379"
but I end up with this error message:
ERROR: The Compose file './docker-compose.yml' is invalid because:
services.server-test.ports contains an invalid type, it should be a number, or an object
Any idea ?
And btw it seems that the expose is not even needed in my first case.
Just for some background, I am setting up mediawiki on a raspberry pi3 for a personal learning project.
I have followed the guide from https://peppe8o.com/personal-mediawiki-with-raspberry-pi-and-docker/ and have been able to follow all but the very last step of running 'docker-compose up -d' and get the error below (I have also pasted the contents of my docker-compose.yml)
I would greatly appreciate if anyone could spot the issue here as I have tried a number of things
(removing and adding spaces in lines 6 & 17 etc....)
pi#raspberrypi:~/mediawiki $ docker-compose up -d
ERROR: yaml.parser.ParserError: while parsing a block mapping
in "./docker-compose.yml", line 6, column 3
expected <block end>, but found '-'
in "./docker-compose.yml", line 17, column 3
Contents of docker-compose.yml:
# My MediaWiki
# from peppe8o.com
version: '3'
services:
mediawiki:
image: mediawiki
restart: unless-stopped
ports:
- 8080:80
links:
- database
volumes:
- mediawiki-www:/var/www/html
#After initial setup, download LocalSettings.php to the same directory as
#this yaml and uncomment the following line and use compose to restart
#the mediawiki service
- ./LocalSettings.php:/var/www/html/LocalSettings.php
database:
build: .
restart: unless-stopped
volumes:
- mediawiki-db:/var/lib/mysql
volumes:
mediawiki-www:
mediawiki-db:
Kind regards
Layerz
I have the following docker-compose file and getting this error:
The Compose file './docker-compose.yaml' is invalid because: Unsuported config for service: 'pihole'
docker-compose.yml:
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
ports:
- "53:53/tcp"
- "53:53/udp"
- "67:67/udp"
- "80:80/tcp"
- "443:443/tcp"
environment:
TZ: 'Europe/Zurich'
WEBPASSWORD: 'mySuperSecrectPW'
volumes:
- './etc-pihole/:/etc/pihole/'
- './etc-dnsmasq.d/:/etc/dnsmasq.d/'
dns:
- 127.0.0.1
- 1.1.1.1
cap_add:
- NET_ADMIN
I already stripped every argument that is not absolutely necessary, but still getting the same error. Sorry if that is a stupid question to ask, but I am new to the whole docker topic and still learning.
Compose files that do not declare a version are considered “version 1”. In those files, all the services are declared at the root of the document.
See Compose file versions.
Try adding version: '3.7' or whatever version you like at the top level.
Here is my docker-compose yaml file.
version: '2.1'
services:
myservice:
environment:
- MYENVVAR={"1": "Hello"}
This gives me the following parsing error when I run docker-compose
ERROR: yaml.parser.ParserError: while parsing a block mapping
in "./my_docker_compose_.yml", line 6, column 9
expected <block end>, but found '}'
in "./my_docker_compose_.yml", line 6, column 111
How can I escape my JSON object properly so it gets sent into the container as the value of environment variable MYENVVAR?
You should define this variable as:
'FOOBAR={"foo": "bar"}'
In short:
version: '3.3'
services:
nginx:
ports:
- '80:80'
volumes:
- '/var/run/docker.sock:/tmp/docker.sock:ro'
restart: always
logging:
options:
max-size: 1g
environment:
- 'FOOBAR={"foo": "bar"}'
- a=test
image: nginx
The similar question was raised on docker bug tracking system:
https://github.com/docker/compose/issues/3878
You can validate or experiment with docker-compose settings online
by visiting a web page:
https://composerize.com/