I try to learn about container, but i have a problem with my docker-compose.yml file, after i run the docker compose up, i always get the same error:
"ERROR: yaml.scanner.ScannerError: mapping values are not allowed
here"
even if i changed the mount path to docker volume, i got the same error, this is my yml file
version: "3"
services:
database:
image: mariadb
ports:
- "3260:3260"
volumes:
- /home/randy/Desktop/Latihan/wordpress-mariadb/mariadb:var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
wordpress:
image: wordpress
ports:
- "2000:80"
volumes:
- /home/randy/Desktop/Latihan/wordpress-mariadb/wordpress:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: root
depends_on:
- database
links:
- database
It appears that your yaml is invalid. When I face these types of issues, what I will do is use a site called http://www.yamllint.com/ which will validate the syntax for you.
This yaml based on your example is valid:
Note: You can use 4 spaces (or 2 which I prefer), but never use tabs.
version: "3"
services:
database:
environment:
MYSQL_ROOT_PASSWORD: root
image: mariadb
ports:
- "3260:3260"
volumes:
- "/home/randy/Desktop/Latihan/wordpress-mariadb/mariadb:var/lib/mysql"
wordpress:
image: wordpress
ports:
- "2000:80"
volumes:
- /home/randy/Desktop/Latihan/wordpress-mariadb/wordpress:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: root
depends_on:
- database
links:
- database
Related
I follow the tutorial in here . When I'm in docker-compose.yml, I can't make the correct file, because the indentation not true. This is my docker-compose.yml:
# Version
version: '3.1'
# Setup
services:
# PHP
php:
depends_on:
- db
image: docker-php-dev
restart: always
ports:
- 5000:80
volumes:
- ./development:/var/www/html
# PHPMyAdmin
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 5050:80
environment:
PMA_HOST: db
# MySQL
db:
image: mysql:5.7
restart: always
volumes:
- wordpress_db:/var/lib/mysql
environment:
MYSQL_DATABASE: wordpress
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
# Volumes
volumes:
wordpress_db:
wordpress_uploads:
I always get error when I run docker-compose up -d. Can someone tell me how to make correct docker-compose.yml file?
You are referencing to a bad document which loss all indent, you should reference to compose file to see how a good compose file should look.
In basic, after write a compose file, you should use docker-compose config to check if the format is ok or not.
For your scenario, the workable fix is next, FYI:
# Version
version: '3.1'
# Setup
services:
# PHP
php:
depends_on:
- db
image: docker-php-dev
restart: always
ports:
- 5000:80
volumes:
- ./development:/var/www/html
# PHPMyAdmin
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 5050:80
environment:
PMA_HOST: db
# MySQL
db:
image: mysql:5.7
restart: always
volumes:
- wordpress_db:/var/lib/mysql
environment:
MYSQL_DATABASE: wordpress
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
# Volumes
volumes:
wordpress_db:
wordpress_uploads:
I want to create a .yml file that i can execute to use wordpress with mysql. I'm new about docker, docker compsoe so my code is:
web:
image: wordpress
links:
- mysql
environment:
- WORDPRESS_DB_PASSWORD=sample
ports:
- "127.0.0.3:8080:80"
mysql:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=sample
- MYSQL_DATABASE=wordpress
I do docker-compose up and i obtain this error:
ERROR: In file './docker-compose.yml', service 'image' must be a mapping not a string.
Anyone can help me?
This is a yaml formatting error.
You should format it like this
web:
image: wordpress
links:
- mysql
environment:
- WORDPRESS_DB_PASSWORD=sample
ports:
- "127.0.0.3:8080:80"
mysql:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=sample
- MYSQL_DATABASE=wordpress
indentation is wrong near mysql: Please correct the indentation as below
web:
image: wordpress
links:
- mysql
environment:
- WORDPRESS_DB_PASSWORD=sample
ports:
- "127.0.0.3:8080:80"
mysql:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=sample
- MYSQL_DATABASE=wordpress
You may validate the yml here https://onlineyamltools.com/validate-yaml
While running "docker-compose up" getting error
ERROR: yaml.scanner.ScannerError: mapping values are not allowed here
in "./docker-compose.yml", line 8, column 14
My docker compose file as below;
postgres:
image: postgres:9.4.21
environment:
POSTGRES_USER: myusername
POSTGRES_PASSWORD: myPass
ports:
-'5432:5432'
volumes:
~/.docker-volumes/mobydock/postgresql/data:/var/lib/postgresql/data
redis:
image: redis: 5.0.5
ports:
- '6379:6379'
volumes:
~/.docker-volumes/mobydock/redis/data:/var/lib/redis/data
mobydock:
build: .
command: gunicorn -b 0.0.0.0:8000 --reload --access-logfile - "mobydock.app:create_app()"
environment:
PYTHONUNBUFFERED: true
links:
- postgres
- redis
volumes:
- .:/mobydock
ports:
- '8000:8000'
I have tried by changing some signs before the volumes path.
I want to compose the docker file with postgres and redis images.
I'm beginner to Docker and doing this first time.
Your main issue is YAML syntax not being respected - if you are new to YAML you can find plenty of resources on the web - such as:
you must use two spaces for indentation of each mapping
when listing elements (such as volumes or ports) you must use - for each element in the list
when using strings with YAML characters (such as :) it's better to quote them (i.e. image: "redis:5.0.5" instead of image: redis: 5.0.5
You also have a few docker-compose syntax related issues:
Volumes is a not a proper list and you'd better use absolute path instead of relative ones (do not use ~/path in Compose), for example:
volumes:
- /home/user/.docker-volumes/mobydock/redis/data:/var/lib/redis/data
In your file, image will be read as an element of volumes, i.e. your indentation is not correct. Instead of using:
# YAML will interpret image as being under the volume key
volumes:
- /home/user/.docker-volumes/mobydock/redis/data:/var/lib/redis/data
image: [...]
You should have:
# mind the space indentation !
volumes:
- /home/user/.docker-volumes/mobydock/redis/data:/var/lib/redis/data
image: [...]
This indentation error is also present on most of the other elements, check the Docker Compose syntax to know the ordering of each elements.
You can use a YAML Linter such as this one to help solve these YAML syntax issues.
postgres:
image: postgres:9.4.21
environment:
POSTGRES_USER: myusername
POSTGRES_PASSWORD: myPass
ports:
-'5432:5432'
volumes:
- ~/.docker-volumes/mobydock/postgresql/data:/var/lib/postgresql/data
redis:
image: redis: 5.0.5
ports:
- '6379:6379'
volumes:
- ~/.docker-volumes/mobydock/redis/data:/var/lib/redis/data
mobydock:
build: .
command: gunicorn -b 0.0.0.0:8000 --reload --access-logfile - "mobydock.app:create_app()"
environment:
PYTHONUNBUFFERED: true
links:
- postgres
- redis
volumes:
- .:/mobydock
ports:
- '8000:8000'
yaml is indent sensitive
volumes is a list, so you should write :
volumes:
- ~/.docker-volumes/mobydock/redis/data:/var/lib/redis/data
Moreover your file is incorrectly indented, it should be written this way :
postgres:
image: "postgres:9.4.21"
environment:
POSTGRES_USER: myusername
POSTGRES_PASSWORD: myPass
ports:
-'5432:5432'
volumes:
- ~/.docker-volumes/mobydock/postgresql/data:/var/lib/postgresql/data
redis:
image: "redis:5.0.5"
ports:
- '6379:6379'
volumes:
- ~/.docker-volumes/mobydock/redis/data:/var/lib/redis/data
mobydock:
build: .
command: 'gunicorn -b 0.0.0.0:8000 --reload --access-logfile - "mobydock.app:create_app()"'
environment:
PYTHONUNBUFFERED: true
links:
- postgres
- redis
volumes:
- .:/mobydock
ports:
- '8000:8000'
I followed multiple guides and tutorials.
This is my docker-compose file.
It gives the following error,
services.mysql.environment.volumes contains ["mysql_data:/var/lib/mysql"], which is an invalid type, it should be a string, number, or a null
And it creates a volume with the name _volumename?
I just don't seem to get the mistake i made.
version : '3'
services:
mysql:
container_name: auth_db
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: supersecret
MYSQL_DATABASE: name
MYSQL_USER: user
MYSQL_PASS: supersecret2
volumes:
- mysql_data:/var/lib/mysql
ports:
- 3306:3306
auth-service:
build: ./authservice
volumes:
- ./authservice:/usr/src/app
ports:
- 5000:5000
volumes:
mysql_data:
Some more information.
If i change the volume line to
volumes: "- mysql_data:/var/lib/mysql"
The docker-compose file will compile but
docker volume ls gives this output
local 4fa81a11596c2b67c2bb799d54afc6009ebcd82fcd10acae53a5aeefd005fd36
local 8636df909155569e8ebf0649f4c192616d0b6778d5eb7932b1f9542db55a07d8
local 832739c89f3b33ad0a1974ad7dc2ee9342373f904af3b2be5934331bae50b5e6
local e5bb4a869f54ce3200d5a1fe129bc1f8ee46515cf03d9dd2ff327430d792117b
local e35a38127fcb07702a58133883a021aa56c4aad6c439d254f32a119ad380d808
local hell_mysql_data
My current dir where the docker-compose file is located is HELL that why i think it got the prefix from
Your issue is regarding indentation, volumes and ports must be top level first inside your service definition, as follows:
version : '3'
services:
mysql:
container_name: auth_db
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: supersecret
MYSQL_DATABASE: name
MYSQL_USER: user
MYSQL_PASS: supersecret2
volumes:
- mysql_data:/var/lib/mysql
ports:
- 3306:3306
auth-service:
build: ./authservice
volumes:
- ./authservice:/usr/src/app
ports:
- 5000:5000
volumes:
mysql_data:
I have a basic Symfony4 setup and I have an issue with loading speed.
Currently I'm trying the docker-sync tool, it's up and running, but it seems that it doesn't do anything, speed stays the same.
Here is my current setup:
docker-compose.yml:
version: '3'
services:
apache:
build: .docker/apache
container_name: sf4_apache
ports:
- 80:80
volumes:
- .docker/config/vhosts:/etc/apache2/sites-enabled
- .:/home/wwwroot/sf4
depends_on:
- php
mysql:
image: mysql
command: "--default-authentication-plugin=mysql_native_password"
container_name: sf4_mysql
restart: always
volumes:
- ./data/db/mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: sf4
MYSQL_USER: sf4
MYSQL_PASSWORD: sf4
php:
build: .docker/php
container_name: sf4_php
volumes:
- .:/home/wwwroot/sf4
environment:
- maildev_host=sf4_maildev
depends_on:
- mysql
links:
- mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: sf4_phpmyadmin
environment:
PMA_HOST: mysql
PMA_PORT: 3306
ports:
- 8080:80
links:
- mysql
docker-sync.yml
version: "2"
options:
verbose: true
syncs:
appcode-native-osx-sync: # tip: add -sync and you keep consistent names as a convention
src: './'
# sync_strategy: 'native_osx' # not needed, this is the default now
sync_excludes: ['ignored_folder', '.ignored_dot_folder']
In this case I synced my entire Symfony application folder, but it doesn't help. docker-sync is up and running as well as all my containers, but performance is still slow. Any other ideas what could I do? I found that one of the solutions is to move the vendor folder out of shared files. How would I do that?
Problem solved. More info about performance on MAC OS here https://docs.docker.com/docker-for-mac/osxfs-caching/
So I mounted my volumes using delegated like this:
apache:
build: .docker/apache
container_name: sf4_apache
ports:
- 80:80
volumes:
- .docker/config/vhosts:/etc/apache2/sites-enabled:delegated
- .:/home/wwwroot/sf4:delegated
depends_on:
- php
Default skeleton Symfony 4 project now loads in less than 1 second. It is still kinda slow, but it's ten times faster than before. :)