A simple yet powerful solution to streamline local development while keeping heavy services on remote servers. This project creates lightweight Docker proxy images that forward traffic to remote services via SSH. Ideal for scenarios where you want to develop locally but use resource-intensive services like databases, ELK stacks, or other backend services hosted remotely.
This tool solves a common challenge in microservices development: the need to have instant feedback loop and run resource-intensive services locally at the same time. Instead of running heavy services like ELK Stack, databases, or machine learning models on your development machine, this tool creates lightweight proxy containers that forward traffic to the actual services running on a remote server.
- π₯ Dramatically reduced local resource usage.
- π Faster local development setup and β‘οΈ instant feedback loop.
- π» Work with production-like environments locally (mostly staging environments).
- π Secure SSH-based communication.
- π Seamless integration with existing docker compose files.
The tool creates a proxy Docker image that replaces the actual service image in your local docker compose file.
When the proxy container starts, it:
- Establishes an SSH connection to the remote server.
- Identifies the target service container on the remote server.
- Sets up port forwarding from your local machine to the remote container.
- Maintains the SSH connection for the duration of the container's life.
- Docker and Docker Compose installed locally.
- SSH access to the remote server.
- Docker and Docker Compose running on the remote server.
- Clone this repository:
git clone /~https://github.com/amhoba2014/docker-compose-local-development-port-mapper
cd docker-compose-local-development-port-mapper
- Generate and copy your SSH key:
cp /path/to/your/existing/ssh/key ./assets/ssh_key
- Set proper permissions:
chmod 600 ./assets/ssh_key
- Configure your remote server settings:
REMOTE_USER
: Username of the remote server that SSH key is created for.REMOTE_IP
: IP address of the remote server.REMOTE_PATH
: Path on the remote server to the directory containing the docker-compose.yml.REMOTE_BASE_COMPOSE_COMMAND
: The base docker compose command that is used on remote server to spin up containers.
nano ./assets/configuration.py
- Build the image:
cd docker-compose-local-development-port-mapper
bash build.sh
- Modify your local
docker-compose.yml
:
Replace the original service images with the port mapper image:
services:
heavy_service:
image: port_mapper:latest
environment:
- SERVICE_NAME=heavy_service
- SERVICE_PORT=8080
- Start your development environment:
docker compose up
Converting an ELK stack service to use port mapping:
This is part of a bigger docker-compose.yml
file running on a dev or staging server.
elasticsearch:
build:
context: ../elasticsearch
target: dev
ports:
- "9200:9200"
This is part of our local docker-compose.yml
file, shall run locally.
elasticsearch:
image: port_mapper:latest
environment:
- SERVICE_NAME=elasticsearch
- SERVICE_PORT=9200
- Never commit SSH keys to version control and use this project locally and share it with colleagues over a trusted wire (USB drive or local network).
- Use dedicated keys for the port mapper.
- Regularly rotate SSH keys.
- Works only with docker compose based setups (which I know most organisations do not use them in staging). Can be tweaked to support Kubernetes and VPC (GCP, AWS, Azure) based setups.
- A slight latency, dependent on the network connection type.
- Requires high speed and stable internet connection (optic fiber works best).
This project is licensed under the MIT License - see the LICENSE file for details.
Inspired by the need for efficient local development at my previous job.
This is more like a SRE/DevOps tooling and type of work, which I almost do most of the times for both myself and my colleagues.