Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rodolfobandeira committed Jan 28, 2018
0 parents commit 096b97c
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM nginx:alpine
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# docker-share-files

#### Description:

This Docker repository starts an HTTP server on port 8080 (http://localhost:8080) showing the famous "index of" listing all files from the local folder `./shared-files`. It is a great way to quickly share files through the network. You can get your private IP with `ifconfig`(MacOS/Linux/*BSD) or`ipconfig`(Windows).

**How it really works:**

This docker uses the official Nginx docker image based on Alpine Linux. I decided to use Alpine because it packs everything that you need on just 18MB. :sunglasses:
When `docker-compose up` is called via command line, it creates two volumes that is shared between the Docker container and host machine.
The fist volume makes the connection between a local folder and your Docker container. That means, if you add a new file inside `./shared-folder`, it will be available automatically on the web interface. (Of course you need to reload the page).
The second volume make possible you customize the Nginx config. That being said, it points `./config/default.conf` to `/usr/share/nginx/html`

We have two folders under this project:

shared-folder | config
------------ | -------------
Just add any file here and when you start your docker, they will be listed to anyone download it | Here we have our Nginx `default.conf` file. Wherever you change here, will be reflected inside your docker. After changing something, keep in mind that you will need to restart your Nginx, so the easiest way is just restarting your docker container.
If you add an `index.html` your "index of" feature will be gone. Sometimes could be useful. Did I mention that you also can create subfolders here? | `./config/default.conf` points to `/etc/nginx/conf.d/default.conf`. The same way, `./shared-folder` points to (Docker) `/usr/share/nginx/html` folder.

`./config/default.conf`:

```nginx
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
autoindex on;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
```

`./docker-compose.yml`

```yaml
version: '2'

services:
web:
build: .
volumes:
- ./config/default.conf:/etc/nginx/conf.d/default.conf
- ./shared-folder:/usr/share/nginx/html
ports:
- 8080:80
```
##### Lets see this working:
1) `git clone https://github.com/rodolfobandeira/docker-share-files.git`

2) `docker-compose build`

3) `docker-compose up`

Open your browser and try the address: `http://localhost:8080`. You must see something like this:

![index of](config/img.png)

---

Questions? [@rodolfobandeira](https://twitter.com/rodolfobandeira)
15 changes: 15 additions & 0 deletions config/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server {
listen 80;
server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
autoindex on;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Binary file added config/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '2'

services:
web:
build: .
volumes:
- ./config/default.conf:/etc/nginx/conf.d/default.conf
- ./shared-folder:/usr/share/nginx/html
ports:
- 8080:80

1 change: 1 addition & 0 deletions shared-folder/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Example 1

0 comments on commit 096b97c

Please sign in to comment.