Docker Community Forums

Share and learn in the Docker community.

How to attach container with another disk for reuse

i have provision aws ec2 instance which is docker host. In that, i have created dockerfile with the copy instruction to get copy of my application from the specified directory . Now i have created another volume in aws ec2 instance and attached with instance (its not partition it is another disk).
how can i attach that volume to the container so next time my container get data from there not by using copying instruction.
Please help

This technique is the most popular one used by DevOps teams. Referred to as data volumes in Docker, it offers the following benefits:

Data volumes can be shared and reused across multiple containers.
Changes made to a data volume are made directly, bypassing the engine’s storage backend image layers implementation.
Changes applied to a data volume will not be included when the image gets updated.
Data volumes are available even if the container itself is deleted.

The volume for the ec2 host is mounted?
Mount the volume for the host, you may need to create a file system for your application.
commands for ec2
lsblk (will show the volume path i.e /dev/xvdc)
mkfs.xfs /dev/xvdc
mount /dev/xvdc/ /home/$USER/myapp ( make sure myapp directory exists)
Make sure you update /etc/fstab or the mount will not persist after host restart.

Now the host has an exposed volume.
Copy your application to that volume.

YOu can use a bind-mount(-v) to run your application from the volume.
docker run -v /home/$USER/myapp:/container/path/to/run/app/from …
Let us know iff that was helpful.
Good Luck.!

in my dockerfile i have instruction of copy for my application. if i dont put copy instruction so what should i write in dockerfile for volume.

Drop the copy…
Volume attribute is not required…

how to check that exposed volume and
how to copy of application to that volume
can u please help me in that

After the volume is mounted like I showed above…
df -h
will show tath /dev/xvdc is mounted on /home/$USER/myapp
IFF you can; mount the app directory, do not copy.
cp -r /home/$USER/development/myapp/ /home/$USER/for/docker/myapp