How can I fix this issue with Yaml file? - docker

Hi I am trying to run docker-compose build --no-cache but I keep getting errors.
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 5
docker-compose.yml:
Please help me to to format this I looked online but I couldn't find any linter that could do this I keep getting errors.
Thanks.
This is my docker composer file:
s is my docker file docker-compose.yml
version: '3'
services:
#PHP-FPM service
app:
build:
context: .
dockerfile: Dockerfile
container_name: store
restart: unless-stopped
tty: true
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker-files/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
-app-network
#Nginix service
webserver:
image: nginx-alpine
container_name: store-webserver
restart: unless-stopped
tty: true
ports:
- "8100:80"
- "8143:443"
volumes:
- ./:/var/www
- ./docker-files/nginx/conf.d:/etc/nginx/conf.d/
networks:
-app-network
#MariaDB service
db:
image: mariadb:10.5.6
container_name: store-mariadb
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: store
MYSQL_USER: store
MYSQL_PASSWORD: root
volumes:
- mariadbData:/var/lib/mysql
- ./docker-files/mariadb/my.cnf:/etc/mysql/my.cnf
networks:
-app-network
#Volumes
volumes:
mariadbData:
driver: local
#Networks
networks:
app-network:
driver: bridge

I have noticed some spacing issues on your YAML file, one of them is that the version and services sections are not on the same level, you have to know that docker-compose files and YAML have a strict syntax and a spacing might ruin everything for you here is a fix to your compose file, make sure to learn and read more about docker-compose documentation.
Not sure what's the behavior of your environment but here is a correct YAML syntax for your example:
version: '3'
services:
#PHP-FPM service
app:
build:
context: .
dockerfile: Dockerfile
container_name: store
restart: unless-stopped
tty: true
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker-files/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginix service
webserver:
image: nginx-alpine
container_name: store-webserver
restart: unless-stopped
tty: true
ports:
- "8100:80"
- "8143:443"
volumes:
- ./:/var/www
- ./docker-files/nginx/conf.d:/etc/nginx/conf.d/
networks:
- app-network
#MariaDB service
db:
image: mariadb:10.5.6
container_name: store-mariadb
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: store
MYSQL_USER: store
MYSQL_PASSWORD: root
volumes:
- mariadbData:/var/lib/mysql
- ./docker-files/mariadb/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#Volumes
volumes:
mariadbData:
driver: local
#Networks
networks:
app-network:
driver: bridge

Related

Docker-Compose: service "xxx" depends on undefined service "xxx": invalid compose project

So I looked at this article: link
And I don't see the problem I made, so that's why I am asking.
The error I am getting is:
service "Appback" depends on undefined service -Sql-server: invalid compose project
And my docker-compose.yml file looks like this:
version: '3.8'
services:
Sql-server:
image: mysql:latest
environment:
MYSQL_DATABASE: *****
MYSQL_USER: ****
MYSQL_PASSWORD: *****
MYSQL_ROOT_PASSWORD: *****
ports:
- 3306:3306
expose:
- 3306
volumes:
- db:/var/lib/mysql
networks:
- appnetwork
Appback:
build:
context: ./AppBack
dockerfile: Dockerfile
ports:
- 8080:8080
depends_on:
-Sql-server:
condition: service_started
networks:
- appnetwork
appfront:
build:
context: ./appfront
dockerfile: Dockerfile
ports:
- 3000:3000
depends_on:
-Appback:
condition: service_started
networks:
- appnetwork
volumes:
db:
networks:
appnetwork:
driver: bridge
I don't see where the problem might be as I am also new to docker compose.
You should separate the -Sql-server: with a space - Sql-server: from the first hyphen character.
I saw the same error when you have -Appback: in the next few lines.

Why are docker volumes not created?

I am running Flask and MySQL using docker-compose.yaml.
Although I have specified a volume, the volume has not been created.
Why is this?
docker-compose.yaml
version: '3'
services:
api:
build: python
container_name: api_server_flask
ports:
- "5000:5000"
tty: true
environment:
TZ: Asia/Tokyo
FLASK_APP: app.py
depends_on:
- db
networks:
- app_flask
db:
build: mysql
container_name: db_server_flask
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: pass
MYSQL_DATABASE: testdb
TZ: Asia/Tokyo
volumes:
- ./db-flask-data/:/var/lib/mysql
command: mysqld
networks:
- app_flask
volumes:
db-flask-data:
networks:
app_flask:
driver: bridge
You need to remove the relative path as follows:
volumes:
- db-flask-data/:/var/lib/mysql
It is explained here: https://docs.docker.com/storage/volumes/#use-a-volume-with-docker-compose
Actually, you are creating a named volume under /var/lib/docker/volumes/db-flask-data when you are specifying the following command:
volumes:
db-flask-data:

docker-compose + symfony in windows env

i've installed docker (windows 10) with wsl2 (ubuntu distro) and added my docker-compose.yml
version: '3'
services:
web:
image: nginx:1.20.1
container_name: web
restart: always
ports:
- "80:80"
volumes:
- ./nginx.d.conf:/etc/nginx/conf.d/nginx.conf
- ./nginx.conf:/etc/nginx/nginx.conf
- ./www/my-app:/app
php:
build:
context: .
dockerfile: myphp.dockerFile
container_name: php
restart: always
depends_on:
- web
volumes:
- ./www/my-app:/app
mysql:
image: mariadb:10.3.28
container_name: mysql
restart: always
depends_on:
- php
environment:
MYSQL_ROOT_PASSWORD: '******'
MYSQL_USER: 'root'
MYSQL_PASSWORD: '******'
MYSQL_DATABASE: 'my-database'
command: ["--default-authentication-plugin=mysql_native_password"]
volumes:
- mysqldata:/var/lib/mysql
- ./my.cnf:/etc/mysql/my.cnf
ports:
- 3306:3306
cache:
image: redis:5.0.3
container_name: cache
restart: always
ports:
- 6379:6379
networks:
- my-network
volumes:
- ./cache:/cache
volumes:
mysqldata: {}
networks:
my-network:
driver: "bridge"
So my symfony code is in the /www/my-app window's folder. This includes the /www/my-app/vendor too.
My application is running extremely slow (50-70 seconds). If i'm correct it's because the vendor folder is huge (80MB) and docker creates an image of it every time. Other discussions mentioned that vendor folder sould be moved into a new volume, and here i'm stuck with it. How to move and mount that in this case, and how should the docker-compose.yml look like after it?

The Compose file './docker-compose.yml' is invalid because: Unsupported config option

I have the following docker-compose file and getting this error,
The Compose file './docker-compose.yml' is invalid because: Unsupported config option
docker-compose.yml:
version: "3"
services:
webserver:
build:
context: ./bin/webserver
container_name: 'png-webserver'
restart: 'always'
ports:
- "81:81"
- "444:444"
links:
- mysql
volumes:
- /var/www/vhost/dev.ivacy.com:/var/www/html
- ${PHP_INI-./config/php/php.ini}:/usr/local/etc/php/php.ini
- ${VHOSTS_DIR-./config/vhosts}:/etc/apache2/sites-enabled
- ${LOG_DIR-./logs/apache2}:/var/log/apache2
networks:
vpcbr:
ipv4_address: 10.5.0.5
mysql:
build: ./bin/mysql
container_name: 'png-mysql'
restart: 'always'
ports:
- "3306:3306"
volumes:
- /var/www/docker-compose-lamp/bin/mysql/db:/docker-entrypoint-initdb.d
- ${MYSQL_DATA_DIR-./data/mysql}:/var/lib/mysql
- ${MYSQL_LOG_DIR-./logs/mysql}:/var/log/mysql
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: ivacy_muti_site
MYSQL_USER: root
MYSQL_PASSWORD: password
networks:
vpcbr:
ipv4_address: 10.5.0.6
depends_on:
- mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: 'png-phpmyadmin'
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
ports:
- '8081:81'
volumes:
- /sessions
networks:
vpcbr:
ipv4_address: 10.5.0.7
depends_on:
- mysql
- webserver
redis:
container_name: 'png-redis'
image: redis:latest
ports:
- "6379:6379"
networks:
vpcbr:
ipv4_address: 10.5.0.8
networks:
vpcbr:
driver: bridge
ipam:
config:
- subnet: 10.5.0.0/16
gateway: 10.5.0.1
You've indented networks into the services block.
networks should be at version level
version: '3.8'
services:
web:
build:
args:
version: 0.0.1
context: .
dockerfile: Dockerfile
networks:
- back-tier
expose:
- 8080
ports:
- 8080:8080
networks:
back-tier:
driver: bridge

phpMyAdmin not accessible from Docker

I have the following docker-compose file:
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: ./vDocker/php/php.Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./vDocker/.env:/var/www/.env
- ./vDocker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www
- ./vDocker/.env:/var/www/.env
- ./vDocker/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.22
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: translive
MYSQL_ROOT_PASSWORD: gio123
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./vDocker/mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
depends_on:
- db
restart: unless-stopped
tty: true
ports:
- "8080:8080"
environment:
PMA_PORT: 3306
PMA_HOST: db
PMA_USER: root
PMA_PASSWORD: gio123
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
I have four services. Three of them work fine and no problem at all, but phpmyadmin doesn't work at all. The thing is all is work fine, database, webserver, but not phpMyAdmin. When I try to go to localhost:8080, it says site can't be reached. I don't know what's going on. What am I missing?

Resources