Headless way to setup Raspberry-Pi and Docker

Oct 25, 2019 · 4 min read

I got raspberry-pi 4 with canakit. In this post I’m gonna discuss about setting up raspbian OS, configuring SSH, wifi setup and configuring docker on raspberry-pi. The information about assembling raspberry-pi 4 canakit can be found in this video.

Setup Raspberry-Pi

1. Identify SD card

Connect SD card to computer and find the disk(SD card) name of the SD card with diskutil. This command will return available disk list. You can find the SD card name at the bottom of the list. In my case /dev/disk2 is the name of the SD card.

2. Format SD card

Format SD card with ExFat format. Then unmount SD card if SD card was automatically mounted.

3. Burn raspbian image to SD card

Download raspbian image and mount it to SD card. I can do it via dd command. It will add raspbian image into boot partition in the SD card.

4. Enable SSH

SSH is not enabled by default on raspberry-pi. To enable SSH, I need to place an empty file named ssh (no extension) in to the boot partition of the SD card.

5. Add wifi network info

I’m gonna connect raspberry-pi into wifi network. To do that I need to add another file wpa_supplicant.conf into the boot partition of the SD card. This file need to popup with wifi network informations. When booting the pi this file will be copied to the main partition’s /etc/wpa_supplicant location and replace whatever is there.

I have created wifi hotspot on mac-book with internet sharing and connected the raspberry-pi into that hotspot. Read more about internet sharing on mac-os in here. I have added my wifi hotspot name/password in to ssid and psk fields.

6. Boot raspberry-pi from SD card

Now everything set to boot the raspberry-pi from SD card. eject SD card from the computer and inset into raspberry-pi. Then Plug a USB-C power supply cable into the power port. Wait till few seconds until booting up the raspberry-pi.

7. Find IP address of raspberry-pi

To SSH into raspberry-pi I need to find the IP address of the raspberry-pi. In latest raspberry-pi’s comes with default host name raspberry-pi.local. I can directly connect to this host via SSH. In old raspberry-pi version I need to find the IP address via arp or nmap commands.

arp returns devices found on the local network, including PCs, routers, iPhones, and iPads, displaying both their LAN IP address as well as their individual MAC address.

nmap(network mapper) command can be use to detect what hosts are available on the network, what services (application name and version) those hosts are offering, what operating systems (and OS versions) they are running, what type of packet filters/firewalls are in use, and dozens of other characteristics. When creating hotspot on mac, it generates new subnet. I can find the subnet and scan the hosts available on that subnet via nmap.

8. SSH into raspberry-pi

After finding the ip addresses I can connect to raspberry-pi via SSH. The default username is the pi, password is the raspberry.

Setup docker

1. Install docker

After connecting to raspberry-pi I can install the docker packages via apt package manager.

2. Install docker-compose

Next step is to install docker-compose. I can do that via pip python package manager.

3. Run docker

The CPU architecture of raspberry-pi is ARM(not x86/x64 by Intel or AMD). The docker images build on x86/x64 architecture will not work on raspberry-pi. If I run x86/x64 based docker image on raspberry-pi it will causes an error. To run docker image on raspberry-pi I need to build it with compatible to ARM CPU architecture. To do that I can build the images based on arm32v6/alpine or resin/rpi-raspbian base image. Following is an example mongodb docker image that I have built based on resin/rpi-raspbian:jessie base image.

This docker image can be built from any computer(ex linux, mac-os, rabberry-pi), push to docker hub and run on raspberry-pi. In my scenario I have built the image from mac-os.

Backup SD card

Once raspberry-pi is setup, I can take a backup of the SD card with all the installed packages and configurations. It’s good idea to take backup time to time. If raspberry-pi get corrupt I can restore the backup image without redoing whole setup from the beginning. The backup image can also be use to setup new raspberry-pi as well. Following is the way to take a backup image from SD card and restore.


  1. https://desertbot.io/blog/headless-raspberry-pi-4-ssh-wifi-setup


Have less, be more


Written by


Scala, Golang with Vim and Hockey: What else does a man need to be happy :)



Have less, be more

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade