Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker compose: meaning of {} in volume definition

What is the meaning of {} in volume definition?

For example

version: '2'

volumes:
  dataelasticsearch: {}

services:   
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:5.4.3
    volumes:
      - ./dataelasticsearch:/usr/share/elasticsearch/data
like image 787
Dušan Maďar Avatar asked Feb 21 '19 13:02

Dušan Maďar


People also ask

What does volumes mean in Docker compose?

Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. While bind mounts are dependent on the directory structure and OS of the host machine, volumes are completely managed by Docker.

What is Z in docker volume?

The z option tells Docker that two containers share the volume content. As a result, Docker labels the content with a shared content label. Shared volume labels allow all containers to read/write content. The Z option tells Docker to label the content with a private unshared label.

What is docker volume types?

Docker volumes are used to persist data from within a Docker container. There are a few different types of Docker volumes: host, anonymous, and, named. Knowing what the difference is and when to use each type can be difficult, but hopefully, I can ease that pain here.

What flag do we use to set a docker volume?

-v or --mount flag The -v or --volume flag was used for standalone containers, and the --mount flag was used for swarm services. However, starting with Docker 17.06, we can also use --mount with standalone containers.


1 Answers

It's just an empty mapping. It just means that no extra options were given to the named volume.

From the tests I have done, this is no different from leaving it blank like:

volumes:
   dataelasticsearch:

The docker-compose docs do not give any more insights into this.

One more thing: you are defining a named volume at the top but then you are binding a mounted volume in the service:

volumes:
  - ./dataelasticsearch:/usr/share/elasticsearch/data

Here ./dataelasticsearch basically creates a folder in your local directory which is mounted as a volume. If you want this feature, you do not need the named volume at all.

like image 113
Manish Dash Avatar answered Sep 22 '22 05:09

Manish Dash