10 BusyBox Recipes
We push out 10 handy busybox recipes!
1. Minimal Interactive Shell Environment
This recipe creates a lightweight container for an interactive shell, ideal for debugging or minimal command-line interactions in resource-constrained environments.
Dockerfile:
FROM busybox:latest
# Set the working directory
WORKDIR /app
# Add a simple entrypoint script
RUN echo '#!/bin/sh' > /entrypoint.sh && \
echo 'echo "Welcome to the minimal BusyBox shell."' >> /entrypoint.sh && \
echo 'exec /bin/sh' >> /entrypoint.sh && \
chmod +x /entrypoint.sh
# Expose no ports as this is shell-only
ENTRYPOINT ["/entrypoint.sh"]
To build and run: docker build -t minimal-shell . followed by docker run -it minimal-shell.
2. Simple Static HTTP File Server
This recipe sets up a basic HTTP server using BusyBox's built-in httpd utility to serve static files, suitable for serving documentation or small websites.
Dockerfile:
FROM busybox:latest
# Create a directory for web content
RUN mkdir -p /www
# Add sample HTML content
RUN echo '<html><body><h1>Hello from BusyBox HTTP Server</h1></body></html>' > /www/index.html
# Expose the default HTTP port
EXPOSE 80
# Run the httpd server in the foreground
CMD ["httpd", "-f", "-v", "-h", "/www"]
To build and run: docker build -t static-http . followed by docker run -p 8080:80 static-http. Access via http://localhost:8080.
3. Network Diagnostic Tool Container
This recipe provides a container with network utilities like ping, nslookup, and netstat for troubleshooting network issues.
Dockerfile:
FROM busybox:latest
# Install additional symlinks if needed (BusyBox already includes most)
RUN ln -s /bin/busybox /bin/ping && \
ln -s /bin/busybox /bin/nslookup && \
ln -s /bin/busybox /bin/netstat
# Set an entrypoint for interactive diagnostics
ENTRYPOINT ["/bin/sh"]
# Default command for non-interactive runs
CMD ["-c", "echo 'Run network commands like ping or nslookup.'"]
To build and run: docker build -t net-diag . followed by docker run -it net-diag to enter the shell for diagnostics.
4. Cron Job Scheduler for Periodic Tasks
This recipe configures a container to run cron jobs, such as periodic backups or checks, using BusyBox's crond.
Dockerfile:
FROM busybox:latest
# Create a crontab file
RUN mkdir -p /etc/cron.d && \
echo '* * * * * echo "Cron job running at $(date)" >> /var/log/cron.log' > /etc/cron.d/example
# Set up logging
RUN touch /var/log/cron.log
# Run crond in the foreground
CMD ["crond", "-f", "-L", "/var/log/cron.log"]
To build and run: docker build -t cron-scheduler . followed by docker run -d cron-scheduler. Monitor logs with docker logs <container_id>.
5. File Synchronization Utility Container
This recipe uses BusyBox's rsync (via symlink) for file synchronization, useful for mirroring directories in a containerized backup scenario.
Dockerfile:
FROM busybox:latest
# Create symlinks for rsync
RUN ln -s /bin/busybox /usr/bin/rsync
# Create source and destination directories
RUN mkdir /source /dest
# Add sample files
RUN echo 'Sample file' > /source/file.txt
# Entry point to run rsync
ENTRYPOINT ["rsync", "-avz", "/source/", "/dest/"]
To build and run: docker build -t file-sync . followed by docker run -v /host/source:/source -v /host/dest:/dest file-sync for host-mounted volumes.
6. DNS Query Tool Container
This recipe focuses on DNS-related tools like nslookup and host for querying domain information.
Dockerfile:
FROM busybox:latest
# Symlink for DNS tools
RUN ln -s /bin/busybox /bin/nslookup && \
ln -s /bin/busybox /bin/host
# Interactive shell for queries
ENTRYPOINT ["/bin/sh"]
# Default command example
CMD ["-c", "nslookup example.com"]
To build and run: docker build -t dns-query . followed by docker run dns-query for a one-time query or -it for interactive mode.
7. Lightweight Logging Aggregator
This recipe creates a container that tails logs or aggregates simple logs using BusyBox utilities like tail and cat.
Dockerfile:
FROM busybox:latest
# Create a log directory
RUN mkdir /logs
# Add a sample log file
RUN echo 'Initial log entry' > /logs/app.log
# Run tail on the log file
CMD ["tail", "-f", "/logs/app.log"]
To build and run: docker build -t log-aggregator . followed by docker run -v /host/logs:/logs log-aggregator to monitor host logs.
8. Basic Wget Downloader Container
This recipe uses BusyBox's wget for downloading files from the web, suitable for scripted fetches in automation pipelines.
Dockerfile:
FROM busybox:latest
# Symlink for wget if needed (already available)
RUN ln -s /bin/busybox /usr/bin/wget
# Set working directory for downloads
WORKDIR /downloads
# Entry point for wget
ENTRYPOINT ["wget"]
# Default arguments for example download
CMD ["-O", "example.txt", "https://example.com"]
To build and run: docker build -t wget-downloader . followed by docker run -v /host/downloads:/downloads wget-downloader https://example.com/file.
9. Environment Variable Inspector
This recipe inspects and displays environment variables using env and printenv, useful for configuration verification in deployments.
Dockerfile:
FROM busybox:latest
# Symlink for env tools
RUN ln -s /bin/busybox /bin/env && \
ln -s /bin/busybox /bin/printenv
# Run env to display variables
CMD ["env"]
To build and run: docker build -t env-inspector . followed by docker run --env MY_VAR=value env-inspector to see injected variables.
10. Simple Text Processing Pipeline
This recipe sets up a container for text manipulation using tools like grep, sed, and awk for processing input streams.
Dockerfile:
FROM busybox:latest
# Symlinks for text tools (already included in BusyBox)
RUN ln -s /bin/busybox /bin/grep && \
ln -s /bin/busybox /bin/sed && \
ln -s /bin/busybox /bin/awk
# Interactive shell for processing
ENTRYPOINT ["/bin/sh"]
# Default command example
CMD ["-c", "echo 'Sample text' | grep 'text' | sed 's/text/processed/'"]
To build and run: docker build -t text-processor . followed by docker run -i text-processor < input.txt for piped input.