Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM mirror.gcr.io/library/alpine:latest

# Install base tools
# Install base tools and nginx
RUN apk update && apk add --no-cache \
bash \
curl \
Expand All @@ -23,7 +23,7 @@ RUN apk update && apk add --no-cache \
coreutils \
mongodb-tools \
postgresql15-client \
py3-flask
nginx

# Set up build arguments (provided by buildx)
ARG TARGETOS
Expand All @@ -45,12 +45,9 @@ ENV PATH="/usr/local/go/bin:${PATH}"
# Verify Go installation
RUN go version

# Copy the Flask app
COPY app.py /app.py
# Expose default HTTP port
EXPOSE 8080

# Expose port 5000
EXPOSE 5000

# Run the Flask app
CMD ["python3", "/app.py"]
# Command to run nginx
CMD ["nginx", "-g", "daemon off;", "-c", "/etc/nginx/nginx.conf"]

175 changes: 86 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
Here's the updated README that includes both the new HTTP/2 examples and the original `ping` example:

---

# Lanyard - A Versatile Networking Toolkit Docker Image

**Lanyard** is a Docker image based on Alpine Linux that includes a comprehensive set of networking tools along with a simple Flask API. This image allows you to either run the Flask application or execute any of the included networking utilities directly.
**Lanyard** is a Docker image based on Alpine Linux that includes a comprehensive set of networking tools and a lightweight Nginx server with HTTPS and HTTP/2 support. This image allows you to serve static files securely or execute any of the included networking utilities directly.

## Table of Contents

- [Included Tools](#included-tools)
- [Getting Started](#getting-started)
- [Running the Flask API](#running-the-flask-api)
- [Running Nginx](#running-nginx)
- [Running Networking Tools](#running-networking-tools)
- [Flask Application](#flask-application)
- [Nginx Configuration](#nginx-configuration)
- [HTTP/2 Support](#http2-support)
- [Building the Docker Image Locally](#building-the-docker-image-locally)
- [Usage Examples](#usage-examples)
- [Notes](#notes)
Expand All @@ -17,6 +22,7 @@

The Docker image includes the following tools:

- `bash`
- `curl`
- `traceroute`
- `openssl`
Expand All @@ -36,27 +42,27 @@ The Docker image includes the following tools:
- `coreutils`
- `mongodb-tools`
- `postgresql-client`
- `py3-flask`
- **Go** (installed minimally)
- `nginx`

## Getting Started

### Running the Flask API
### Running Nginx

To run the Flask API, execute the following command:
To run the Nginx server:

```sh
docker run --rm -d -p 5000:5000 quay.io/rzago/lanyard:latest
docker run --rm -d -p 8080:8080 quay.io/rzago/lanyard:latest
```

- `--rm`: Automatically removes the container when it exits.
- `-d`: Runs the container in detached mode.
- `-p 5000:5000`: Maps port 5000 of the host to port 5000 of the container.
- `-p 8080:8080`: Maps port 8080 of the host to port 8080 of the container.

Once the container is running, you can access the API at [http://localhost:5000/](http://localhost:5000/). You should see the message:
Once the container is running, you can access the server at [http://localhost:8080](http://localhost:8080). You will see the response:

```
Hello, World from Lanyard!
<h1>Hello from Lanyard</h1>
```

### Running Networking Tools
Expand All @@ -81,121 +87,112 @@ PING google.com (142.250.79.14): 56 data bytes
round-trip min/avg/max = 7.189/7.298/7.509 ms
```

## Flask Application
## Nginx Configuration

The Flask application (`app.py`) included in the image is a simple "Hello World" app:
### Default Configuration

```python
from flask import Flask
- **HTTP/2 and HTTP/1.1:** Nginx supports both HTTP/2 and HTTP/1.1.
- **Static Files:** Static files are served from `/usr/share/nginx/html`.

app = Flask(__name__)
### Custom Configuration

@app.route('/')
def hello_world():
return 'Hello, World from Lanyard!'
You can mount custom Nginx configuration files to modify the server's behavior:

if __name__ == '__main__':
app.run(host='0.0.0.0')
```sh
docker run --rm -d -p 8080:8080 -v $(pwd)/my-nginx.conf:/etc/nginx/nginx.conf quay.io/rzago/lanyard:latest
```

## Building the Docker Image Locally
## HTTP/2 Support

If you prefer to build the Docker image locally, use the provided `Dockerfile`:
Nginx in the Lanyard image supports HTTP/2. Below are examples demonstrating HTTP/2 and HTTP/1.1 behavior:

```dockerfile
FROM alpine:latest

# Install base tools
RUN apk update && apk add --no-cache \
curl \
traceroute \
openssl \
iperf \
wget \
busybox-extras \
nmap \
netcat-openbsd \
tcpdump \
mtr \
socat \
bind-tools \
iproute2 \
openssh-client \
python3 \
procps \
coreutils \
mongodb-tools \
postgresql-client \
py3-flask

# Install Go separately in a minimal way
RUN apk add --no-cache --virtual .build-deps go && \
mkdir -p /usr/local/go/bin && \
mv /usr/bin/go /usr/local/go/bin/ && \
apk del .build-deps

# Copy the Flask app
COPY app.py /app.py

# Expose port 5000 for the Flask app
EXPOSE 5000

# Default command to run the Flask app
CMD ["python3", "/app.py"]
```

**Build the image:**
#### Testing HTTP/2

```sh
docker build -t lanyard .
curl --http2 --http2-prior-knowledge http://localhost:8080
```

## Usage Examples
Output:

Here are some examples of how to use the Docker image to run various networking tools.
```html
<h1>Hello from Lanyard</h1>
```

### Run `ping`
#### Testing HTTP/1.1

```sh
docker run --rm lanyard ping -c 4 google.com
curl http://localhost:8080
```

### Run `traceroute`
Output:

```sh
docker run --rm lanyard traceroute google.com
```html
<h1>Hello from Lanyard</h1>
```

### Run `curl`
#### Inspecting HTTP Headers (HTTP/1.1)

```sh
docker run --rm lanyard curl -I https://www.google.com
curl -I http://localhost:8080
```

Output:

```
HTTP/1.1 200 OK
Server: nginx/1.26.2
Date: Mon, 06 Jan 2025 18:06:29 GMT
Content-Type: text/html
Content-Length: 29
Last-Modified: Mon, 06 Jan 2025 18:06:06 GMT
Connection: keep-alive
ETag: "677c1b8e-1d"
Accept-Ranges: bytes
```

### Run `nmap`
#### Inspecting HTTP Headers (HTTP/2)

```sh
docker run --rm lanyard nmap -sV google.com
curl -I --http2 --http2-prior-knowledge http://localhost:8080
```

Output:

```
HTTP/2 200
server: nginx/1.26.2
date: Mon, 06 Jan 2025 18:06:39 GMT
content-type: text/html
content-length: 29
last-modified: Mon, 06 Jan 2025 18:06:06 GMT
etag: "677c1b8e-1d"
accept-ranges: bytes
```

### Run `iperf`
## Building the Docker Image Locally

If you prefer to build the Docker image locally, use the provided `Dockerfile`:

```sh
# As an iperf server
docker run --rm -p 5201:5201 lanyard iperf -s
docker build -t lanyard .
```

# As an iperf client
docker run --rm lanyard iperf -c <server_ip>
## Usage Examples

### Run `ping`

```sh
docker run --rm lanyard ping -c 4 google.com
```

## Notes
### Serve Custom Static Files

Mount a directory containing your static files:

- **Default Behavior:** If no command is specified, the container will run the Flask API.
- **Overriding the Command:** You can run any of the included tools by specifying the command after the image name.
- **Exposed Ports:** Ensure that the ports you intend to use are not blocked by your firewall or used by other applications.
- **Networking:** When running networking tools, you might need to adjust Docker's network settings depending on your environment.
- **Alpine Linux:** The image is based on Alpine Linux for a minimal footprint.
```sh
docker run --rm -d -p 8080:8080 -v $(pwd)/html:/usr/share/nginx/html quay.io/rzago/lanyard:latest
```

---

Feel free to contribute or raise issues if you encounter any problems. Enjoy using Lanyard for all your networking needs!
Feel free to contribute or raise issues if you encounter any problems. Enjoy using Lanyard for all your networking and lightweight web-serving needs!
10 changes: 0 additions & 10 deletions app.py

This file was deleted.

16 changes: 16 additions & 0 deletions custom-nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
events {}

http {
server {
listen 8080;
http2 on;

root /usr/share/nginx/html; # Set the root directory for your static files
index index.html; # Specify the default index file

location / {
try_files $uri $uri/ =404; # Ensure files in the root directory are served
}
}
}

2 changes: 2 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Hello from Lanyard</h1>

Loading