This guide will cover the basic setup and installation of docker and docker-compose on a raspberry pi. This guide is a prequel to many other guides found on this site.
- Any RaspberryPi (3 or 3B+ Recommended)
- MicroSD 16GB+
- USB Keyboard
- Network cable or Wifi to connect to your home network
To run docker on your raspberry pi, we need to install the main filesystem on our microSD card which the pi can boot from. Since we will only use the terminal, there’s no need for installing a desktop environment so download the Raspbian Jessie Light image on their website.
To flash an image onto an sd card, you can use one of the following depending on your current platform
Insert the MicroSD in your pc using a USB card reader or a built-in reader, then open the software for your platform, select the image file and click Flash/Write (you should extract the downloaded zip/7z/gz to get the actual .img file)
When the writing is done, plug in a USB keyboard and screen into your raspberry pi, insert the sd card and power on your pi. If using a network cable connect it now. Wifi will be set-up later.
I recommend using a wired ethernet connection to your raspberry pi, this minimizes the risk of random disconnects due to losing wifi connectivity. I also highly recommend using a static IP for your raspberry, this can be done in your router by assigning a static IP to your raspberry pi’s mac address. Then, to remotely access the pi, I will enable ssh so the USB keyboard and screen are not needed anymore.
Simply connect an ethernet cable to your raspberry pi’s ethernet port, no other steps necessary as long as your router’s DHCP provides an IP. When starting the pi with the network cable attached, the console should print it’s IP when it was able to obtain one.
To enable wifi, you will need to set your country first. This can be done by typing
A gray menu should open. Navigate to “Localization Options” and follow the screenshots below to select your country using the arrow and enter key:
Then to enable wifi, follow these screenshots but provide your access point information
Enter your passphraze and your raspberry pi should connect to your wifi.
Static IP in the router
Setting a static IP in your router is different for each brand and/or model, I’ve got a Netgear R8000. The static IP settings are located under: General Settings -> Lan Settings -> Static Route. You usually have to provide a name, IP and mac address to add the static route to your DHCP. This entry will make sure your raspberry pi always gets the same pre-assigned IP from your router.
Click apply in your router (this will in some cases reboot your router). Then reboot your raspberry pi using “sudo reboot now”. The IP should now be updated to the one set in your router. If not you should be aware that the wifi and ethernet port have different mac addresses. So when you switch from wifi to a wired connection, the raspberry pi won’t match the entered mac address
Once ssh is enabled and your network is connected. You can remotely set up your raspberry pi using Terminal(mac) or putty(windows). To connect simply run “ssh pi@(RASPBERRYPI’S IP)” then fill in the password (raspbian by default). you can also continue using the USB keyboard, the steps remain the same.
Before installing docker, we want to make sure our raspberry pi software is up to date, this can be done by running following commands
sudo apt - get update sudo apt - get -y dist-upgrade
This may take a while. After it is done, we can start installing Docker. First, add docker’s official GDG-Key
curl -fsSL https://download.docker.com/linux/raspbian/gpg | sudo apt-key add -
Then use the following command to add/choose the stable branch from the docker repository
echo "deb [arch=armhf] https://download.docker.com/linux/raspbian stretch stable" | sudo tee /etc/apt/sources.list.d/docker.list
Update sources “apt-get sources” by typing following command
sudo apt-get update
Then for the actual installation
sudo apt-get install docker-ce
Then for the last step, add the docker user, this will stop your ssh session. reconnect when the command is executed
sudo usermod -aG docker pi && logout
To add docker compose, run following command (this will take a while depending on your pi)
sudo apt-get -y install python-setuptools && sudo easy_install pip && sudo pip install docker-compose
To verify docker and docker-compose are installed and working, type docker or docker-compose –version
If both packages print their version correctly, your docker setup is completed.