Skip to content

Instantly share code, notes, and snippets.

@jimboy-701
Last active October 22, 2022 05:24
Show Gist options
  • Save jimboy-701/5194b47e5d1de67d7e69cfe3420f24ef to your computer and use it in GitHub Desktop.
Save jimboy-701/5194b47e5d1de67d7e69cfe3420f24ef to your computer and use it in GitHub Desktop.
How to Install latest Debian and setup Docker on Raspberry Pie 4

How to Install Debian stable on RPI4 and setup Docker Engine Community CE

Download the latest Raspberry Pi OS 64-bit image (Debian base)

You can choose between a Desktop version or a Lite version without xorg & xfce

or get the vanilla Debian Images

Note: Using these images will require a few extra steps to setup which we will also cover below.
The rpi-eeprom package will not be available in the repos so you won't able to update the RPI's firmware if that's required.

Image the OS onto bootable media

The image file will most likely be compressed (7z or zip) so be sure to unzip it.
Flash the downloaded Debian image file to a SDCard or whatever boot storage you're using with an Imaging program.
Eg: BalenaEtcher, Rasberry Pie imager, W32diskImager

Before you boot setup for SecureShell access

To login via ssh you need to first edit two config files to enable remote root access.
Note: you'll most likely need another working Linux system to do this step as Microsoft Windows cannot access a Linux Filesystem natively.

On the RASPIROOT partition edit file "/etc/ssh/sshd_config" Uncomment and change the following entry:
#PermitRootLogin prohibit-password > PermitRootLogin yes

On the RASPIFIRM partition edit file "/sysconf.txt" Add the following entry (without quotes):
root_pw="yourpassword"

Optionally you can change the hostname here as well:
hostname="givenhostname"

Finally let's boot up the RPI

Plug the bootable media into your Pi and boot to it. Now you should be able to SSH into it with this command:
ssh root@deviceip

Once logged into Debian we'll need to make sure everything is up to date

apt update && apt list --upgradable

If apt shows available updated packages to install:

apt dist-upgrade -y && apt autoremove

Be sure to reboot PI if you had to install any major packages: reboot

As mentioned above the following steps only pertain to the vanilla Debian image (skip the numbered steps below if otherwise)

  1. Install sudo along with some other optional utils you may need later
    apt install sudo htop curl wget git build-essential dnsutils

  2. Create a standard User account and it to the sudo group
    adduser username
    usermod -aG sudo username

  3. Verify sudo membership
    getent group sudo

  4. Test run sudo
    su - username
    sudo whoami

Run through the standard setup tool, configure the Raspberry Pie OS, and create a standard User account

sudo dpkg-reconfigure console-setup
sudo raspi-config

Allow new User to ssh and remove root access from ssh:

nano /etc/ssh/sshd_config

Change this part to like so:
PermitRootLogin no

Append the following to sshd_config:
AllowUsers username

Optionally install neofetch and edit the .bashrc file to display system info after logging in via ssh

sudo apt install neofetch
nano ~/.bashrc

Append the following code into .bashrc file to make it work:

if [[ -n $SSH_CONNECTION ]]; then
    clear && neofetch
fi

Before installing Docker we'll need to get some prerequisite packages and other tools

sudo apt install apt-transport-https ca-certificates gnupg-agent software-properties-common python3-pip

Install the Docker Engine (docker-ce, docker-compose, and everything else)

sudo curl -sSL https://get.docker.com | sh

Let's install the latest version of Docker Compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

The latest version of Docker Compose is not compatible with previous versions so you should also install Compose-Switch

curl -fL https://raw.githubusercontent.com/docker/compose-switch/master/install_on_linux.sh | sudo sh

Test Docker Compose with Compose-Switch installed:

docker-compose -v
update-alternatives --display docker-compose

Finally give permissions to your standard User account to manage Docker containers

sudo usermod -aG docker username

Run these commands (without sudo) to verify Docker is installed and functioning correctly:
docker ps
docker run hello-world

Optionally install Portainer CE and initilize it

sudo docker pull portainer/portainer-ce
sudo docker run --restart always -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce

Open up your favorite web browser and login to Portainer with the following address

http://[RASPBERRY_PI_IP_ADDRESS]:9000

If you plan on installing a Pihole docker container you're gonna need to disable the resolved service (otherwise skip)

systemctl stop systemd-resolved
systemctl disable systemd-resolved

Edit resolv.conf and remove \ replace any existing IPs with 8.8.8.8
nano /etc/resolv.conf

References

you need to learn Docker RIGHT NOW!! // Docker Containers 101

BLOCK EVERYTHING w/ PiHole on Docker, OpenDNS and IFTTT

How to Install Portainer on a Raspberry Pi!

Thank you

Please feel free to leave any helpful comments or suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment