Create A Mini File Host for WGET

I needed a way to allow everyone on our local networks to be able to pull files with WGET. I also need the files to be accessible from other docker containers. So, I created this image to make files available via wget but only to our private VPC/VPN.

Created Project in GitLab

I use GitLab to host no just our Git repository but also our docker registry. So I needed to create a Project in order to have a place in the registry for my image.  I did not use the Dockerfile method for this, but I could have.

Project Name: hosted-files

Tomcat Image

I chose Tomcat because I am very familiar with how it works and troubleshooting issues.

Pulled

docker pull tomcat:7.0

Tagged

docker tag <image##.  gitlab.domain.com:5500/laurie/hosted-files:v1

Pushed to GitLab Registry

docker push gitlab.domain.com:5500/laurie/hosted-files:v1

 

Rancher Stack

The next step is to build a stack that uses my image.  So I configured a stack in Rancher for new image.

I used the following docker-compose.yml

Hosted-Files:
  ports:
  - 80:8080/tcp
  labels:
    io.rancher.container.pull_image: always
    io.rancher.scheduler.affinity:host_label: name=rancherpool-pvt ## this makes it run on private instances only.
  image: gitlab.domain.com:5500/laurie/hosted-files:v1  ## changed this to v2 after image update.
  volumes:
  - /efs/data/hosted-files:/usr/local/tomcat/files ## I have an EFS folder for persistent files.

Modification

After I launched the stack, I opened a shell in the running container. I then edited the server.xml file by adding the following to the <host> section.

<Context docBase="/usr/local/tomcat/files" path="/f" />

This tells Tomcat to take the files in the /usr/local/tomcat/files and make them available as:  servername.com/f/filname.

I then committed the running container to a new image called hosted-files:v2

docker commit <imageid> gitlab.domain.com:5500/laurie/hosted-files:v2

 

Next I created a folder on EFS for Hosted files and copied a file named “test-file.txt” file to it.

/efs/data/hosted-files

I set the folder to be mounted to /usr/local/tomcat/files image:

rancher-hosted-files1Because I am using the Route53 service from the Rancher Catalog, and have opened port 80 on my container, Rancher automatically created a DNS entry for the Hosted Files container

hosted-files.hosted-files.environment.domain.com

I created a more friendly DNS entry and pointed it to the automatically created name.

hf.domain.com  CNAME hosted-files.hosted-files.enviroment.domain.com.

The file is now available via wget:

wget http://hf.domain.com/f/test-file.txt

==================================================

Note: I found out about LightTPD afterwards. It would also be a good choice for this project as well. There is also a pre-made docker container for lighttpd here.

 

Other things that could be done:

  • I could add a Load Balancer and SSL certificate to encrypt the connection.
  • I could have created a Dockerfile and used GitLab to build my image. Perhaps this way I could have passed my change to the server.xml at build time.
Follow by Email
Facebook
Google+
http://cloudlady911.com/index.php/2016/10/16/create-a-mini-file-host-for-wget/
LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *