updated env and sh completed

This commit is contained in:
berkay 2025-04-19 19:15:34 +03:00
parent b146e32d50
commit 1ed5cffe45
4 changed files with 281 additions and 33 deletions

7
.env.example Normal file
View File

@ -0,0 +1,7 @@
# MongoDB credentials
MONGO_ROOT_USERNAME=admin
MONGO_ROOT_PASSWORD=change_this_password
# Mongo Express credentials
MONGOEXPRESS_USERNAME=mexpress
MONGOEXPRESS_PASSWORD=change_this_password_too

53
docker-install.sh Normal file
View File

@ -0,0 +1,53 @@
#!/bin/bash
# Docker installation script for LXC container in Proxmox
# Exit on any error
set -e
echo "Starting Docker installation for LXC container..."
# Fix DNS if needed
echo "Checking and fixing DNS configuration..."
if ! grep -q "nameserver" /etc/resolv.conf; then
echo "DNS configuration missing or empty, adding Google DNS servers..."
echo "nameserver 8.8.8.8
nameserver 8.8.4.4" > /etc/resolv.conf
echo "DNS configuration fixed."
fi
# Install basic tools first
echo "Installing basic tools..."
apt update
apt install -y curl wget apt-transport-https ca-certificates gnupg lsb-release
# Update the system
echo "Updating system packages..."
apt update && apt upgrade -y
# Download the Docker installation script
echo "Downloading official Docker installation script..."
curl -fsSL https://get.docker.com -o get-docker.sh
# Make it executable
chmod +x get-docker.sh
# Run the installation script
echo "Running Docker installation script..."
sh ./get-docker.sh
# Install Docker Compose
echo "Installing Docker Compose..."
curl -L "https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-linux-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# Enable Docker to start on boot
echo "Enabling Docker to start on boot..."
systemctl enable docker
# Verify installations
echo "Verifying installations..."
docker --version
docker-compose --version
echo "Docker installation complete!"
echo "You can now use Docker and Docker Compose in your LXC container."

80
fix-network.sh Normal file
View File

@ -0,0 +1,80 @@
#!/bin/bash
# Network troubleshooting script for LXC containers
# Exit on any error
set -e
echo "Starting network troubleshooting..."
# Check if we can ping IP addresses
echo "Testing basic connectivity..."
if ping -c 2 8.8.8.8 >/dev/null 2>&1; then
echo "✅ Basic network connectivity works (can ping 8.8.8.8)"
else
echo "❌ Cannot ping 8.8.8.8 - basic network connectivity issue"
echo "Checking network interfaces..."
ip a
fi
# Check and fix DNS
echo "Checking DNS configuration..."
if ! grep -q "nameserver" /etc/resolv.conf || ! host archive.ubuntu.com >/dev/null 2>&1; then
echo "❌ DNS resolution not working, fixing..."
# Add Google DNS servers
echo "nameserver 8.8.8.8
nameserver 8.8.4.4" > /etc/resolv.conf
echo "✅ Added Google DNS servers to /etc/resolv.conf"
# Make DNS changes persistent
echo "Making DNS changes persistent..."
mkdir -p /etc/systemd/resolved.conf.d/
cat > /etc/systemd/resolved.conf.d/dns_servers.conf << EOF
[Resolve]
DNS=8.8.8.8 8.8.4.4
FallbackDNS=1.1.1.1
EOF
# Try to restart systemd-resolved if it exists
if systemctl status systemd-resolved >/dev/null 2>&1; then
systemctl restart systemd-resolved
echo "✅ Restarted systemd-resolved"
fi
# Try to restart systemd-networkd if it exists
if systemctl status systemd-networkd >/dev/null 2>&1; then
systemctl restart systemd-networkd
echo "✅ Restarted systemd-networkd"
fi
else
echo "✅ DNS configuration looks good"
fi
# Add hosts entries as a fallback
echo "Adding fallback entries to /etc/hosts..."
if ! grep -q "archive.ubuntu.com" /etc/hosts; then
cat >> /etc/hosts << EOF
185.125.190.36 archive.ubuntu.com
185.125.190.36 security.ubuntu.com
EOF
echo "✅ Added Ubuntu repositories to /etc/hosts"
fi
# Test DNS resolution
echo "Testing DNS resolution..."
if host archive.ubuntu.com >/dev/null 2>&1; then
echo "✅ DNS resolution working for archive.ubuntu.com"
else
echo "❌ DNS resolution still not working for archive.ubuntu.com"
echo "Trying ping with hosts file..."
if ping -c 2 archive.ubuntu.com >/dev/null 2>&1; then
echo "✅ Can ping archive.ubuntu.com using hosts file entry"
else
echo "❌ Still cannot reach archive.ubuntu.com"
echo "This may be a more serious network issue with your LXC container"
fi
fi
echo "Network troubleshooting completed"
echo "Try running 'apt update' now to see if it works"

View File

@ -2,7 +2,21 @@
This guide will walk you through creating and configuring an LXC container in Proxmox that's optimized for running Docker and our MongoDB service. This guide will walk you through creating and configuring an LXC container in Proxmox that's optimized for running Docker and our MongoDB service.
## Step 1: Create a new LXC Container in Proxmox ## Step 1: Download the Ubuntu 22.04 LTS Template
If you don't already have the Ubuntu 22.04 LTS template in your Proxmox server, you'll need to download it first:
1. Log in to your Proxmox web interface
2. Select your node in the server view
3. Go to the "Local" storage (or any storage configured for CT templates)
4. Click on the "Templates" button
5. In the template list, find "ubuntu-22.04-standard" in the list
- If you don't see it, click on "Templates" and then search for "ubuntu-22.04"
- If the template list is empty or doesn't show Ubuntu 22.04, you may need to refresh the list by clicking "Refresh"
6. Click on the template and then click "Download"
7. Wait for the download to complete
## Step 2: Create a new LXC Container in Proxmox
1. Log in to your Proxmox web interface 1. Log in to your Proxmox web interface
2. Select your node in the server view 2. Select your node in the server view
@ -17,7 +31,13 @@ This guide will walk you through creating and configuring an LXC container in Pr
- SSH Public Key: (optionally add your SSH key) - SSH Public Key: (optionally add your SSH key)
- **Template**: - **Template**:
- Select a recent Ubuntu or Debian template (e.g., ubuntu-22.04-standard) - **Best choice**: Ubuntu 22.04 LTS (ubuntu-22.04-standard)
- Reasons:
- Excellent Docker compatibility
- Long-term support until 2027
- Best documentation and community support for Docker
- Most stable kernel features needed for containerization
- Regular security updates
- **Disks**: - **Disks**:
- Storage: (select your storage) - Storage: (select your storage)
@ -38,7 +58,7 @@ This guide will walk you through creating and configuring an LXC container in Pr
5. Click "Finish" to create the container 5. Click "Finish" to create the container
## Step 2: Configure the LXC Container for Docker ## Step 3: Configure the LXC Container for Docker
After creating the container, you need to modify its configuration to support Docker: After creating the container, you need to modify its configuration to support Docker:
@ -67,7 +87,7 @@ lxc.mount.auto: proc:rw sys:rw
5. Start the container 5. Start the container
## Step 3: Install Docker inside the LXC Container ## Step 4: Configure Network and Install Docker
1. Start the container and access its shell: 1. Start the container and access its shell:
@ -76,60 +96,148 @@ pct start <container-id>
pct enter <container-id> pct enter <container-id>
``` ```
2. Update the system: 2. **IMPORTANT: Check if your network interface has an IP address:**
```bash
ip a
```
If your eth0 interface doesn't show an IPv4 address (like 192.168.x.x), you need to configure it first:
```bash
# For Proxmox LXC containers, configure networking from the Proxmox web interface:
1. Exit the container first with 'exit' command
2. In the Proxmox web interface, select your container from the left sidebar
3. Click 'Stop' to stop the container if it's running
4. Go to the 'Network' tab
5. If there's no network interface, click 'Create' to add one:
- Name: eth0
- Bridge: vmbr0 (or your preferred bridge)
- IPv4: DHCP (or Static with your preferred IP configuration)
- IPv4/CIDR: (if using static IP, enter something like 192.168.1.100/24)
- Gateway: (if using static IP, enter your gateway, e.g., 192.168.1.1)
6. If there's already a network interface, click 'Edit' and update the configuration
7. Click 'OK' to save the changes
8. Go back to the 'Summary' tab and click 'Start' to start the container
9. Click 'Console' to access the container
# Alternatively, use the command line on the Proxmox host:
# Stop the container
pct stop <container-id>
# Configure networking (DHCP)
pct set <container-id> -net0 name=eth0,bridge=vmbr0,ip=dhcp
# Or configure with static IP (replace with your network details)
pct set <container-id> -net0 name=eth0,bridge=vmbr0,ip=192.168.1.100/24,gw=192.168.1.1
# Start the container again
pct start <container-id>
pct enter <container-id>
# Verify you now have an IP address
ip a
```
3. Fix network connectivity issues:
```bash
# First, check if you can ping IP addresses
ping -c 4 8.8.8.8
# If you can't ping IPs, check your network interface
ip a
# Check your container's network configuration
cat /etc/network/interfaces
# Check DNS configuration
cat /etc/resolv.conf
# Fix DNS by adding these entries to resolv.conf
echo "nameserver 8.8.8.8
nameserver 8.8.4.4" > /etc/resolv.conf
# Make the DNS changes persistent by editing the systemd-resolved configuration
mkdir -p /etc/systemd/resolved.conf.d/
cat > /etc/systemd/resolved.conf.d/dns_servers.conf << EOF
[Resolve]
DNS=8.8.8.8 8.8.4.4
FallbackDNS=1.1.1.1
EOF
# Restart networking and DNS services
systemctl restart systemd-networkd
systemctl restart systemd-resolved
# Test DNS resolution
host archive.ubuntu.com
```
4. If DNS is still not working, try adding entries to /etc/hosts:
```bash
# Add essential Ubuntu repositories to /etc/hosts
cat >> /etc/hosts << EOF
185.125.190.36 archive.ubuntu.com
185.125.190.36 security.ubuntu.com
EOF
# Test if it works
ping -c 2 archive.ubuntu.com
```
5. Install basic tools:
```bash
apt update
apt install -y curl wget apt-transport-https ca-certificates gnupg lsb-release
```
6. Update the system:
```bash ```bash
apt update && apt upgrade -y apt update && apt upgrade -y
``` ```
3. Install required packages: 7. Install Docker using the official installation script:
```bash ```bash
apt install -y apt-transport-https ca-certificates curl software-properties-common gnupg # Download the Docker installation script
curl -fsSL https://get.docker.com -o get-docker.sh
# Review the script (optional but recommended)
less get-docker.sh
# Run the installation script
sh get-docker.sh
``` ```
4. Add Docker's official GPG key and repository: This script automatically detects your OS, adds the appropriate repositories, and installs Docker and its dependencies.
For Ubuntu: 8. Install Docker Compose:
```bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
```
For Debian:
```bash
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
```
5. Update the package database and install Docker:
```bash
apt update
apt install -y docker-ce docker-ce-cli containerd.io
```
6. Install Docker Compose:
```bash ```bash
curl -L "https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-linux-$(uname -m)" -o /usr/local/bin/docker-compose curl -L "https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-linux-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose
``` ```
7. Verify the installations: 9. Verify the installations:
```bash ```bash
docker --version docker --version
docker-compose --version docker-compose --version
``` ```
8. Enable Docker to start on boot: 10. Enable Docker to start on boot:
```bash ```bash
systemctl enable docker systemctl enable docker
``` ```
## Step 4: Deploy MongoDB using Docker Compose ## Step 5: Deploy MongoDB using Docker Compose
1. Create a directory for your MongoDB service: 1. Create a directory for your MongoDB service:
@ -163,7 +271,7 @@ docker-compose up -d
docker-compose ps docker-compose ps
``` ```
## Step 5: Configure Firewall (Optional but Recommended) ## Step 6: Configure Firewall (Optional but Recommended)
If you're using a firewall on your Proxmox host, make sure to allow traffic to ports 27017 and 8081: If you're using a firewall on your Proxmox host, make sure to allow traffic to ports 27017 and 8081:
@ -177,7 +285,7 @@ iptables -A INPUT -p tcp --dport 27017 -j ACCEPT
iptables -A INPUT -p tcp --dport 8081 -j ACCEPT iptables -A INPUT -p tcp --dport 8081 -j ACCEPT
``` ```
## Step 6: Test the Connection ## Step 7: Test the Connection
From your external machine, test the connection to MongoDB: From your external machine, test the connection to MongoDB: