Ubuntu Docker with OpenCode and SSH
This project provides a complete Docker environment with Ubuntu, OpenCode AI, and SSH access for secure development.
Quick Start
# Build, run, and connect in one command
./build-and-run.sh
Features
- Ubuntu 22.04+ base image with essential development tools
- OpenCode AI pre-installed and ready to use
- SSH server configured for secure remote access
- GitHub CLI included for repository operations
- Volume mounts for persistent configuration and project files
- Non-root user for enhanced security
Usage
Basic Commands
# Full setup (build, run, connect)
./build-and-run.sh
# Build Docker image only
./build-and-run.sh build
# Run container (assumes image exists)
./build-and-run.sh run
# Connect to existing container
./build-and-run.sh connect
# Stop and remove container
./build-and-run.sh stop
# Rebuild everything
./build-and-run.sh rebuild
# Show help
./build-and-run.sh help
Environment Variables
Set these variables to enhance functionality:
# GitHub token for authentication
export GH_TOKEN="your_github_token"
# OpenAI API key for OpenCode
export OPENAI_API_KEY="your_openai_key"
# Anthropic API key for Claude models
export ANTHROPIC_API_KEY="your_anthropic_key"
# Run with environment variables
GH_TOKEN=xxx ./build-and-run.sh
SSH Access
- Host: localhost
- Port: 2222
- Username: ubuntu
- Password: ubuntu
Connect manually:
ssh -p 2222 ubuntu@localhost
Inside the Container
Once connected via SSH:
# Start OpenCode AI
opencode
# Navigate to your workspace
cd /home/ubuntu/workspace
# Use GitHub CLI
gh repo list
# Edit files
vim filename.js
Volume Mounts
The following directories are mounted for persistence:
~/.ssh/id_ed25519→/home/ubuntu/.ssh/id_ed25519(read-only)~/.ssh/id_rsa→/home/ubuntu/.ssh/id_rsa(read-only)~/.config/opencode→/home/ubuntu/.config/opencode~/.local/share/opencode→/home/ubuntu/.local/share/opencode./workspace→/home/ubuntu/workspace
Security Notes
- SSH runs on port 2222 to avoid conflicts
- Root login is disabled via SSH
- Non-root user 'ubuntu' with sudo privileges
- SSH keys are mounted read-only for security
Troubleshooting
Container won't start
# Check if Docker is running
sudo systemctl status docker
# Check existing containers
docker ps -a
# Remove old container
./build-and-run.sh stop
SSH connection fails
# Check if container is running
docker ps | grep opencode-ssh
# Check container logs
docker logs opencode-ssh
# Try connecting with verbose output
ssh -v -p 2222 ubuntu@localhost
OpenCode not working
# Check OpenCode installation
docker exec -it opencode-ssh which opencode
# Reinstall if needed
docker exec -it opencode-ssh curl -fsSL https://opencode.ai/install | bash
Development Workflow
- Clone your project into the current directory
- Run
./build-and-run.sh - Once connected via SSH, navigate to
/home/ubuntu/workspace - Start OpenCode with
opencode - Work on your project with AI assistance
File Structure
.
├── Dockerfile # Container definition
├── build-and-run.sh # Main script
├── README.md # This file
└── workspace/ # Your project files (mounted)
Languages
Shell
74.3%
Dockerfile
25.7%