Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I reference the service name docker-compose.yml

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}
like image 478
Mandragor Avatar asked May 16 '16 08:05

Mandragor


People also ask

What file does Docker Compose use to define services?

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.

Can we assign name to our container in docker?

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.


1 Answers

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 services db and web, then Compose starts containers named myapp_db_1 and myapp_web_1 respectively.

like image 66
Dmitry Logvinenko Avatar answered Sep 29 '22 19:09

Dmitry Logvinenko