In docker-compose.yaml, is there a way to reference the service name (web, database), so that in the code below, the volumes would be created as /store/web
for web and /store/database
for database ?
---
version: '2'
services:
web:
volumes:
- /store/${reference_service_name_above}
database:
volumes:
- /store/${reference_service_name_above}
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application's services.
You can assign memorable names to your docker containers when you run them, using the --name flag as follows. The -d flag tells docker to run a container in detached mode, in the background and print the new container ID.
I suppose you can use the variable COMPOSE_PROJECT_NAME
: https://docs.docker.com/compose/reference/envvars/#compose_project_name
Sets the project name. This value is prepended along with the service name to the container on start up. For example, if your project name is
myapp
and it includes two servicesdb
andweb
, then Compose starts containers namedmyapp_db_1
andmyapp_web_1
respectively.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With