What is the difference between volumes-from and volumes?

In short:

  1. volumes_from mounts from other containers.
  2. volumes mounts defined inline.
  3. links connects containers.

A little bit more explained:

  1. volumes_from mounts volumes from other containers. For example if you have data only containers and you want to mount these data only containers in the container that has your application code.

  2. volumes is a the inline way to define and mount volumes. If you read #17798 you can see that named volumes can replace data only containers in most cases.

    The simplest is then to use volumes. Since you can reuse them by naming them.

  3. links is different. Because it does not mount. Instead it connects containers. So if you do:

    app:
      container_name: app_container
      links:
        - db
    

    That means that if you connect to app_container with docker exec -it app_container bash and try ping db you will see that container is able to resolve ip for db.

    This is because docker creates a network between containers.

Leave a Comment

File not found.