In this tutorial we’re going to explore how to view and edit the contents of a Volume mounted in a running container.
This tutorial is based on the container created in the Introduction:
Verify that the container is running
1 beekube ps
And verify that the contaienr has a volume attached
1 beekube ps --json
--jsonreturn a JSON-formatted output that can be easily managed with jq
A Volume is a persistent disk mounted in a running container. A volume can be mounted over multiple containers; we’re going to exploit this feature to mount service container on an already mounted volumes to have access to the files.
We need an nginx web server with avolume
1 2 beekube volume create http_data --size 5 beekube run --name some-nginx -p 80:80 -v http_data:/usr/share/nginx/html nginx
NGINX container does not expose SSH for security reasons. To inspect the files we can run a container that expose SSH and attach it to the
We can use bubuntu, a customized Ubuntu image provided by us that comes with an sshd daemon and some tools to edit files.
Choose a password for ssh and run the container
1 beekube run --name ssh -p 46587:22 -v http_data:/usr/share/nginx/html -e SSH_ROOT_PASS=<password> beekube/bubuntu
--name ssh: this is the name for the container
-p 46587:22: expose the port 22 of the container (SSH) on internet using a different port - bogon networks scan the internet for opened ssh port - this is not secure, it just reduce the failed logins
-v http_data:/usr/share/nginx/html: we mount the same volume used by nginx
-e SSH_ROOT_PASS=<password>: set an environment variable with the root password
To retrieve the container hostname, run
beekube ps. Now we can ssh in our new container:
1 ssh root@<ssh-publish> -p 46587
Now it is possible to edit the files using vim or nano, or by scp!