Want to make storage of your website running on Docker persistent or to share same storage to any regions of AWS ?
Here my main aim is to make the storage of my website running on Docker in an instance in AWS and also to share the same storage to any regions of the AWS without any loss of data.
Step 1: Create a instance and login via SSH using Putty.
Here I am launching an instance named linux_os with linux AMI .
Now to access this created O.S we need to connect by SSH protocol. For this I am using Putty ( PuTTY is an SSH ).But putty accept .ppk format key but I have created .pem format , so we have to convert it for this I used puttygen. Click load > search for key . And give name either same or different name.
Click Yes and select Save private key. Login with ec2-user@IP. IP of instance to be used. Click ope and you'll be logined to the linux_os.
#sudo su - root ( to get root power ) #yum install docker -y ( install docker ) # service docker start ( start docker ) #chkconfig docker on #docker pull vimal13/apache-webserver-php ( Pull docker image )
To let anyone view your website of from your linux O.S set inbounds to TCP with port (I used 81 ).
Step 2: Create volume (EBS) and attach to this linux_os .
This new created volume will be our external hard disk or as a pendrive which will store data of OS. Now attach this storage ( pendrive1 ) to running instance ( linux_os )
Hence external storage is created .
Now 3 steps to be followed as it is an Block Storage. 1. Partition of hard disk. # fdisk -l ( list of hard disks ) # fdisk /dev/xvdf1 ( go inside this hard disk ) # n ( To create partition ) # w ( To save ) 2. Format the hard disk. # mkfs.ext4 /dev/xvdf1 3. Mount. # mkdir /myweb # mount /dev/xvdf1 /myweb ( To mount external hard disk to /myweb ) # df -h ( To view the status )
Now my external hard disk is connected to /myweb folder. So any data stored in this folder will be copied same to this storage.
Step 3: Launch the container with apache webserver and mount.a
Now launch the container with docker image which has apache-webserver and mount /myweb to /var/www/html with port any port say 81.
Now /myweb will act as a storage of /var/www/html and previously we mounted /myweb to pendrive1( /dev/xvdf1 ) . Hence storage of wesite will be stored to pendrive1.
So, any data stored in /myweb will be stored in webserver running on docker (/var/www/html location). And we can view the website with IP of instance with port 81 .
Hence storage of website is persistent. If you terminate your docker container or terminate your O.S , data is stored safely on external hard disk ( pendrive1 ).
Rollback :
If you want create backup of your storage at a particular point of time in past we can save that storage using Snapshots . Click Action and create snapshot.
Now snapshot can be created at different point of time in order to retrive or Rollback data at any point of time.
From this snapshot we can :
- Create Volume and can attach to any new O.S .
2. We can copy this snapshot to any other regions of AWS globally.
Here I have copied to Singapore region . Now I can create volume of this snapshot and attach to new O.S with same data .
Hence , this is a great use-case of docker and AWS with great use of snapshot to create backup .