I'm using this docker-compose.yml.
And I wanna make simpler and inherrit configuration, if its possible.
version: '2'
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
web_one:
container_name: "web_one"
build:
context: ./
dockerfile: web.docker
volumes:
- ./../one:/var/www
environment:
- VIRTUAL_HOST=whoami_one.local
links:
- app_one
app_one:
container_name: "app_one"
build:
context: ./
dockerfile: app.docker
volumes:
- ./../one:/var/www
links:
- db
web_two:
container_name: "web_two"
build:
context: ./
dockerfile: web.docker
volumes:
- ./../two:/var/www
environment:
- VIRTUAL_HOST=whoami_two.local
links:
- app_two
app_two:
container_name: "app_two"
build:
context: ./
dockerfile: app.docker
volumes:
- ./../two:/var/www
links:
- db
I have 15 sites with same configuration.
Can I make config simpler? Like this:
version: '2'
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
one:
extends:
file: common-services.yml
volumes:
- ./../one:/var/www
environment:
- VIRTUAL_HOST=whoami_one.local
two:
extends:
file: common-services.yml
volumes:
- ./../two:/var/www
environment:
- VIRTUAL_HOST=whoami_two.local
Or better?
Thank you!
UPDATE 31 Aug 2021 In the latest docker compose there's support for profiles https://docs.docker.com/compose/profiles/ so this problem would be perfectly solved by that new feature.
Another way is to create no-op services that depend on other services.
For example, in the following docker-compose.yml I have two namespaces, dev for services needed when developing the app, and metrics for services related to visualizing app metrics (since I'm not interested instarting those when developing).
version: "3"
services:
dev:
image: tianon/true
depends_on: ["postgres", "keycloak"]
metrics:
image: monroe/noop
depends_on: ["grafana"]
postgres: ...
keycloak: ...
grafana: ...
Related
version: '3.8'
volumes:
datafiles:
services:
mysql:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
container_name: mysql_ecommerce
environment:
- MYSQL_ROOT_PASSWORD=12345
- MYSQL_TCP_PORT=3308:3306
volumes:
- datafiles:/var/lib/mysql
restart: always
website:
container_name: web_ecommerce
build:
context: .
dockerfile: Dockerfile
enviroment:
- MYSQL_DBHOST=mysql
- MYSQL_DBPORT=3306
- MYSQL_DBUSER=root
- MYSQL_DBPASS=12345
- MYSQL_DBNAME=
ports:
- 8082:80
- 8083:443
depends_on:
- mysql
You may need to check your docker-compose file and ensure it follows the correct indentation.
version: '3.8'
services:
mysql:
website:
I am trying to compose my project, but got this error:
It was not possible to connect to the Redis server(s). UnableToConnect
on localhost:6379/Interactive
How can I fix or find a problem? Thank you.
docker-compose.yml:
version: '3.4'
services:
catalogdb:
image: mongo
cartdb:
image: redis:alpine
eshop.catalog.api:
image: ${DOCKER_REGISTRY-}eshopcatalogapi
build:
context: .
dockerfile: EShop.Catalog.API/Dockerfile
eshop.cart.api:
image: ${DOCKER_REGISTRY-}eshopcartapi
build:
context: .
dockerfile: EShop.Cart.API/Dockerfile
volumes:
mongo_data:
docker-compose.override.yml:
version: '3.4'
services:
catalogdb:
container_name: catalogdb
restart: always
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db
cartdb:
container_name: cartdb
restart: always
ports:
- "6379:6379"
eshop.catalog.api:
container_name: catalog.api
environment:
- ASPNETCORE_ENVIRONMENT=Development
- "DatabaseSettings:ConnectionString=mongodb://catalogdb:27017"
depends_on:
- catalogdb
ports:
- "8000:80"
eshop.cart.api:
container_name: cart.api
environment:
- ASPNETCORE_ENVIRONMENT=Development
- "CacheSettings:ConnectionString=basketdb:6379"
depends_on:
- cartdb
ports:
- "8001:80"
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
Lets suppose that I have got a ten services in docker-compose and every this service need the same extra_hosts with a four records.
I would like to define extra_hosts once and only include it to every service.
Is it possible?
version: '3.7'
services:
web:
build:
context: ./apache
dockerfile: dockerfile_apache2
image: debian:latest
container_name: hsthttp1
extra_hosts:
- "somehost1:162.242.195.82"
- "somehost2:162.242.195.83"
- "somehost3:162.242.195.84"
- "somehost4:162.242.195.85"
web2:
build:
context: ./apache
dockerfile: dockerfile_apache2
image: debian:latest
container_name: hsthttp2
extra_hosts:
- "somehost1:162.242.195.82"
- "somehost2:162.242.195.83"
- "somehost3:162.242.195.84"
- "somehost4:162.242.195.85"
web3:
build:
context: ./apache
dockerfile: dockerfile_apache2
image: debian:latest
container_name: hsthttp3
extra_hosts:
- "somehost1:162.242.195.82"
- "somehost2:162.242.195.83"
- "somehost3:162.242.195.84"
- "somehost4:162.242.195.85"
Yes, it's possible to use Extension fields to define reusable fragments since compose version 3.4:
For your situation, you can use next:
docker-compose.yaml:
version: '3.7'
x-extra_hosts:
&default-extra_hosts
- "somehost1:162.242.195.82"
- "somehost2:162.242.195.83"
- "somehost3:162.242.195.84"
- "somehost4:162.242.195.85"
services:
web:
image: debian:latest
container_name: hsthttp1
extra_hosts: *default-extra_hosts
web2:
image: debian:latest
container_name: hsthttp2
extra_hosts: *default-extra_hosts
web3:
image: debian:latest
container_name: hsthttp3
extra_hosts: *default-extra_hosts
Above, we define a global &default-extra_hosts which later in every service we can reference it with *default-extra_hosts.
You can use docker-compose config to quick check the effect as next:
shubuntu1#shubuntu1:~/try$ docker-compose config
services:
web:
container_name: hsthttp1
extra_hosts:
- somehost1:162.242.195.82
- somehost2:162.242.195.83
- somehost3:162.242.195.84
- somehost4:162.242.195.85
image: debian:latest
web2:
container_name: hsthttp2
extra_hosts:
- somehost1:162.242.195.82
- somehost2:162.242.195.83
- somehost3:162.242.195.84
- somehost4:162.242.195.85
image: debian:latest
web3:
container_name: hsthttp3
extra_hosts:
- somehost1:162.242.195.82
- somehost2:162.242.195.83
- somehost3:162.242.195.84
- somehost4:162.242.195.85
image: debian:latest
version: '3.7'
I have a yml file with a configuration to run two containers. Here's the file:
web:
build: ./web
ports:
- "8000:8000"
restart: always
volumes:
- website:/www/
nginx:
build: ./nginx
ports:
- "80:80"
restart: always
links:
- web
volumes:
- website:/www/
volumes:
website:
When I run this I always get the following error:
The Compose file '.\docker-compose.yml' is invalid because:
Unsupported config option for volumes: 'website'
I have googled this and I think this is good as it is now. What is wrong with it?
i think you should add version and services in docker-compose file.
version: '3'
services:
web:
build: ./web
ports:
- "8000:8000"
restart: always
volumes:
- website:/www/
nginx:
build: ./nginx
ports:
- "80:80"
restart: always
links:
- web
volumes:
- website:/www/
volumes:
website:
reference :
docker compose file
getting start with docker-compose