I’ve been getting back into doing a bit of testing with vSphere Integrated Containers 1.1 (VIC for short) in my lab. One of the things that I am very interested in revisiting is how to do persistence of data with VIC and “Containers as VMs”. I did some work on this in the past, but a lot has changed since I last looked at it (which was VIC v0.4.0). In this post, we’ll download a nginx web server image and start it up. We’ll look at how you can make changes to the web server while it is running, but how these are lost when the container is stopped. We will then create a volume, move the nginx web server files to our volume, and then restart the container, specifying our volume as the source for the web server files.
Let’s begin with a straight forward nginx deployment. In this example, I am going to launch it in interactive mode, and drop into the bash shell so we can look around. If you want to know more about getting started with VIC v1.1 and deploying the Virtual Container Host (VCH) with the docker endpoint, check out this post here. At this point, my VCH is already deployed, so I’m just going to continue with deploying the nginx container:
E:\vic> docker -H 10.27.51.39:2376 --tls run -it -p 80:80 nginx /bin/bash Unable to find image 'nginx:latest' locally Pulling from library/nginx 36a46ebd5019: Pull complete a3ed95caeb02: Pull complete 57168433389f: Pull complete 332ec8285c50: Pull complete Digest: sha256:c15f1fb8fd55c60c72f940a76da76a5fccce2fefa0dd9b17967b9e40b0355316 Status: Downloaded newer image for library/nginx:latest root@92ff66b88fdf:/#
OK – now we are in the container. At this point the web server is not running. We can start the web server as follows:
root@92ff66b88fdf:/# service nginx start
192.168.0.1 - - [12/May/2017:11:11:40 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0" "-" 2017/05/12 11:11:40 [error] 230#230: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "10.27.51.39" 192.168.0.1 - - [12/May/2017:11:11:40 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0" "-" 2017/05/12 11:11:40 [error] 230#230: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "10.27.51.39" 192.168.0.1 - - [12/May/2017:11:11:40 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0" "-"
root@92ff66b88fdf:/# service nginx stop root@92ff66b88fdf:/# cd /usr/share/nginx/html/ root@92ff66b88fdf:/usr/share/nginx/html# ls 50x.html index.html
root@92ff66b88fdf:/usr/share/nginx/html# sed -e 's/Welcome to nginx/Welcome to Cormacs nginx/' \ index.html >> new_index.html root@92ff66b88fdf:/usr/share/nginx/html# mv new_index.html index.html root@92ff66b88fdf:/usr/share/nginx/html# service nginx start
E:\vic> docker -H 10.27.51.39:2376 --tls volume create -d vsphere --opt VolumeStore=corvols \ --name corvol1 corvol1 E:\vic> docker -H 10.27.51.39:2376 --tls run -v corvol1:/usr/share/nginx2/ -it -p 80:80 \ nginx /bin/bash root@bdf1271cdf35:/# root@bdf1271cdf35:/# df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 994524 0 994524 0% /dev tmpfs 1026528 0 1026528 0% /dev/shm tmpfs 1026528 0 1026528 0% /sys/fs/cgroup /dev/sda 7743120 149716 7177020 3% / tmpfs 65536 8316 57220 13% /.tether /dev/disk/by-label/759d5820c83641f7 999320 1284 929224 1% /usr/share/nginx2
root@bdf1271cdf35:# cd /usr/share/nginx root@bdf1271cdf35:/usr/share/nginx# cp -r html/ ../nginx2 root@bdf1271cdf35:/usr/share/nginx# cd .. root@bdf1271cdf35:/usr/share# ls nginx2/html/ 50x.html index.html root@bdf1271cdf35:/usr/share# cd nginx2/html root@bdf1271cdf35:/usr/share/nginx2/html# sed -e 's/Welcome to nginx/Welcome to Cormacs nginx/' \ index.html >> new_index.html root@bdf1271cdf35:/usr/share/nginx2/html# mv new_index.html index.html root@bdf1271cdf35:/usr/share/nginx2/html# cd root@bdf1271cdf35:~# exit
E:\vic> docker -H 10.27.51.39:2376 --tls run -d -p 80:80 nginx 6696d5aed9b92022cde8becd41170346573c581f493f246014dfe925144e8316
E:\vic> docker -H 10.27.51.39:2376 --tls run -v corvol1:/usr/share/nginx/ -d -p 80:80 nginx d8c49c1846f2566270fe0a78006adc58c5a9caa3dd3faf1b4bde3349cf6e9210
The post Revisiting persistent storage with vSphere Integrated Containers appeared first on CormacHogan.com.