Skip to content

Docker Mount Directory and Static Content Sharing

Ali Hassan edited this page Sep 9, 2022 · 1 revision

Static Content Sharing

Now a days many applications run on cloud virtual space. Many companies build application in virtual space such as Google, Facebook, Tesla and other multinational companies around the world. Some companies use Kubernetes for further advancement in virtual cloud space.Most of time we shared static content with our peers. Such as recent visit in England or any other media file. Now the question is why static content sharing is important in mounted directory in docker engine?

If you had already build something on the docker then you know the answer. Docker doesn't allow us to store files directory directory unless user create volume, bind or temporary volume. The reason is that docker allocate disk over hard-disk which is entirely separately from rest of the application space. Docker provide virtual environment for application. Virtual Environment is similar to boot or hyper-vision operating system. Separate Disk, Different Network Configuration, different IP Configuration etc.

In your application user shared some data over application, because application created in virtual space (docker). Application store files in volume if it was created before.

      [app] -------------------- (volume-create) ********************________________ Files store

Now in your application you want to render file content in your web-page.

      [app] -------------------- (volume access) _____________________ File ************************ (web)

This task is little trivial. Let solve this! Application want to open mounted directory. After that find the file inside the directory. Now relative path of a directory and file name use as link. There may be case that docker directory is not accessible as static, for this static configuration also added. Like in my case

docker_files := http.StripPrefix("/app_data", http.FileServer(http.Dir("./app_data"))) routing.PathPrefix("/app_data/").Handler(docker_files)

"/app_data/" => directory "abx.png" => file name

About Us

Clone this wiki locally