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.
Related
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:
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
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?
I created a Symfony environment with Docker. I then included this file in my web project (skeleton website). But when I try to access my base.html.twig page located in a main folder from the controller, I get this error:
Unable to find template "main/base.html.twig" (looked into: /var/www/templates, /var/www/vendor/symfony/twig-bridge/Resources/views/Form).
How can I solve the problem? I have version 5 of Symfony.
Here is the content of my docker-compose file:
version: '3'
services:
php:
container_name: "php-fpm"
build:
context: ./php
environment:
- APP_ENV=${APP_ENV}
- APP_SECRET=${APP_SECRET}
volumes:
- ${APP_FOLDER}:/var/www
networks:
- dev
nginx:
container_name: "nginx"
build:
context: ./nginx
volumes:
- ${APP_FOLDER}:/var/www
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./logs:/var/log/nginx/
depends_on:
- php
ports:
- "80:80"
networks:
- dev
db:
image: mysql
container_name: "db"
restart: always
volumes:
- db-data:/var/lib/mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
networks:
- dev
phpmyadmin:
image: phpmyadmin
container_name: "phpmyadmin"
restart: always
depends_on:
- db
ports:
- 8080:80
environment:
PMA_HOST: db
networks:
- dev
networks:
dev:
volumes:
db-data:
Your Docker Compose file needs to link local folders with Docker folders.
#docker-compose example
version: "3"
services:
web:
build: .
ports:
- "8080:80"
volumes:
- .:/var/www # Map local folder to Docker
I am setting up the following docker containers with the following 2 docker-compose files:
version: '3.7'
services:
mysql:
image: mysql:5.7
restart: on-failure
environment:
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
volumes:
- db_data:/var/lib/mysql:rw
ports:
- '${MYSQL_PORT}:3306'
networks:
- shared_mysql
php:
build:
context: .
dockerfile: docker/php/Dockerfile
restart: on-failure
volumes:
- '../:/usr/src/app'
user: ${LOCAL_USER}
networks:
- shared_mysql
api_nginx:
image: nginx:1.15.3-alpine
restart: on-failure
volumes:
- '../public/:/usr/src/app'
- './docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro'
ports:
- '21180:80'
depends_on:
- php
networks:
- shared_mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: on-failure
ports:
- '${PHPMYADMIN_PORT}:80'
environment:
PMA_HOST: mysql
MYSQL_USERNAME: ${MYSQL_USER}
MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD}
networks:
- shared_mysql
volumes:
db_data:
networks:
shared_mysql:
version: '3.7'
services:
php:
build:
context: .
dockerfile: docker/php/Dockerfile
restart: on-failure
volumes:
- '../:/usr/src/app'
user: ${LOCAL_USER}
networks:
- api_21s_shared_mysql
auth_nginx:
image: nginx:1.15.3-alpine
restart: on-failure
volumes:
- '../public/:/usr/src/app'
- './docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro'
ports:
- '21181:80'
depends_on:
- php
networks:
- api_21s_shared_mysql
volumes:
db_data:
networks:
api_21s_shared_mysql:
external: true
When I visit http://localhost:21181/, I always get the correct website.
But when I visit http://localhost:21182/, I get http://localhost:21181/ or http://localhost:21182/ random.
I tried to set up the network sepperate.
I'd like it to work with the portnumbers, but I don't want them to be mixed up.
I am hoping someone can help me. Thank you in advance.
When services are started with docker-compose, they are discoverable within the docker network in different ways: by service name, by container name, by IP, etc.
In your case you use the discovery by service name, since in your nginx configuration you have the reference "php:9000".
At this point docker looks for a service named "php" and finds 2. It interprets them as replicas of the same service and sends traffic to them following a round-robin pattern (first request to first instance of the service, second to the second instance of the service, third to the first instance, forth to the second instance, etc.)
Solution
Name the services differently, just like you already do with your nginx services (auth_nginx and api_nginx).
Then in your default.conf for both services change the line referring to php:9000 accordingly.