简体   繁体   中英

how to attach a EBS volume to my container using docker-compose.yml and ecs-cli

I am using docker-compose.yml to define a set of containers. And use ecs-cli compose (service) up to create my application on AWS .

I know AWS ECS comes with 100GB EBS automatically when a container is created. (Even though the EC2 instance that hosts the container only have 8GB of hard drive.) I want to have a persistent storage so that even if I updated my container, it can still point to the same 100GB EBS . I am pretty sure I can do the following to achieve this goal:

Attach an external EBS to the EC2 instance, and use volume in the compose file to attach that volume to the container.

However, I feel there might be a better way to do so on ECS since it gives you 100GB ELB automatically. That is, if I use the above approach, then I am really 'wasting' the 100GB volume that comes with each container. So, what is the best way to achieve this. Could you give an answer in the form of a docker-compose.yml format like the following?

container1:
  image: image1

container2:
  image: image2
  links:
    - "container1"

Not sure if you have already resolved this. Here is working docker-compose.yml for me.

version: '2'
services:
  container1:
    volumes:
      - /var/ebsshare:/ebs
  container2:
    volumes_from:
      - container1:rw

Please make sure your EBS source path(/var/ebsshare) has necessary permissions so docker containers can read and write data to it (chmod 755?).

container2 shares volume from container1 with Read-Write( rw ) permissions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM