Can you please provide an example to sharing a path using volumes_from
from container A to Container B, in addition how container B can access this path after sharing is done.
Thanks
We can also use the | operator to run multiple commands in Docker Compose. The syntax of the | operator is a bit different from the && operator. Here, we added the commands on separate lines. Everything is the same except for the command instruction.
depends_on is a Docker Compose keyword to set the order in which services must start and stop. For example, suppose we want our web application, which we'll build as a web-app image, to start after our Postgres container.
Docker Compose is used to run multiple containers as a single service. For example, suppose you had an application which required NGNIX and MySQL, you could create one file which would start both the containers as a service without the need to start each one separately.
Both the Dockerfile and docker-compose are important resources in the development and deployment of cloud-native applications. But knowing the difference between docker-compose and the Dockerfile is important. The Dockerfile is used to build images, while docker-compose helps you run them as containers.
As documentation said volumes if you are in version 3
you can use The top-level volumes
to define a named volume as db-data
ee code below and you can reference it in every services something like this:
version: "3" services: web: nginx:alpine ports: - "80:80" postgres: image: postgres:9.4 volumes: - db-data:/var/lib/db backup: image: postgres:9.4 volumes: - db-data:/var/lib/backup/data redis: image: redis ports: - "6379:6379" volumes: - ./data:/data volumes: db-data:
version 2.0:
volumes_from
allow you mount all data or volume from another service or container, you have to specify the access level how documentation said volumes from in your code you can use something like this:
version: "2" services: web: image: nginx:alpine ports: - "80:80" volumes_from: - redis:rw postgres: image: postgres:9.4 volumes: - /data/webapp backup: image: postgres:9.4 volumes: - /var/lib/backup/data redis: image: redis ports: - "6379:6379" volumes: - /data/db
To code above redis
define a volume services and then you can use in another container for example web
with volumes_from
look like web service use that volume service specify access level to read and write
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