Skip to content

Instantly share code, notes, and snippets.

@alexanderson1993
Created September 27, 2024 19:54
Show Gist options
  • Save alexanderson1993/27e3c9c0946da19999695a91d8b9ef24 to your computer and use it in GitHub Desktop.
Save alexanderson1993/27e3c9c0946da19999695a91d8b9ef24 to your computer and use it in GitHub Desktop.
Turnkey Reverse Proxied Portainer Script

A script for installing Docker and Portainer CE on an Ubuntu box which you can use to start up all kinds of other apps on the same host.

Make sure you change the appropriate parts of the script, specifically the DEFAULT_EMAIL used for the acme-companion, and the hostnames for the Portainer container.

#!/bin/bash
sudo apt-get udpate
sudo apt-get install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
# Install Docker
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Assign the current user to the docker group
sudo usermod -aG docker $USER
newgrp docker
# Start docker on boot
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
# Todo: Enable a default host -e DEFAULT_HOST=foo.bar.com
docker run --name nginx-proxy --restart=always -d -p 80:80 -p 443:443/tcp -p 443:443/udp -v certs:/etc/nginx/certs -v html:/usr/share/nginx/html -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy
docker run --name nginx-proxy-acme --restart=always -d --volumes-from nginx-proxy -v /var/run/docker.sock:/var/run/docker.sock:ro -v acme:/etc/acme.sh -e "[email protected]" nginxproxy/acme-companion
# Start Portainer
docker volume create portainer_data
docker run -d -p 8000:8000 -e VIRTUAL_HOST=portainer.yourhost.com -e LETSENCRYPT_HOST=portainer.yourhost.com -e VIRTUAL_PORT=9000 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:2.21.2
# Be sure to configure the firewall to allow traffic on port 80 and 443!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment