Raspberry Pi is small computer with wide functionality. It is possible to use it not only for education and learning but also for using it as a server. Linux operating system is used for Raspberry Pi, so it is gives large possibilities. So it can be low cost, power efficient server that costs about 35$. You can buy it on official site https://www.raspberrypi.org/products/ or on http://aliexpress.com
Docker
Now Docker became very popular, it is widely used almost in all projects. It helps to develop and deploy applications without worries about external dependencies. And it is possible to install it on Raspbian - Raspberry Pi official operating system. You can read more about it https://docs.docker.com/
Requirements
So will be required:
- One of the Raspberry Pi models - Raspberry Pi 2B, Rasperry Pi 3B, Raspberry Pi 3B+ or new model Raspberry Pi 4B. May be also first versions also will work, but it will be much slower. Also it uses older architecture ARMv6 and it will be harder to find images for docker. More information about Raspberry Pi models can be found here - https://en.wikipedia.org/wiki/Raspberry_Pi or on official page https://www.raspberrypi.org/
- MicroSD card for at least 16 Gb for operating system, docker and images. It is better to use faster card. I think now the best value price cards are Samsung Evo Plus cards.
- Micro USB power supply that can give at least 2A, bet better is 2.5A
- Case for Raspberry Pi for your choice
- Keyboard and/or mouse only for configuring SSH.
First of all need to install operating system. There are several OS that are supported by Raspberry computer. We will choose official Raspbian Buster. It can be downloaded from official site - https://www.raspberrypi.org/downloads/. You can install Raspbian or Raspbian Lite. I will not describe here how to setup it. There are instructions how to do it: https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up
Configure SSH
Then should configure SSH so it will be possible to connect to Raspberry Pi from another computer, so server will not require mouse and keyboard. If you are using Raspbian, it can be done in Raspberry Pi configuration:
If you are using Raspbian Lite, or you are using shell, then configuration program can be called with this command:
sudo raspi-config
Then select Interface options and then enable ssh:
Now you should be able to connect to your Raspberry Pi using some SSH client, for example Putty. Now server will work in some safe place and it will possible to connect from another device that is in your local network. To get stable connection, I recommend connect Raspberry Pi using wired Ethernet connection rather than using Wi-Fi.
Install Docker
Now at last we will start to setup docker. Setup is rather simple:
curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh
There are two commands divided by && operator: first will download script for installing docker and the second will run it. After couple of minutes Docker will be running on your system. Now docker can be run only using sudo operator. To avoid this make next steps:
- Create docker group if it is not already created.
sudo groupadd docker
2. Add current user to docker group. By default it will be pi user, but you can set also different user
sudo gpasswd -a $USER docker
3. Run command for the changes to take effect
newgrp docker
Docker is installed now! It should be possible to run docker container without sudo command
docker run hello-world
You should see hello message from Docker
Now can try to run different containers which can be found in Docker hub - https://hub.docker.com/. Unfortunately not all containers there can be run on Raspberry Pi because it has ARM architecture. Also selection decreases if you use 32 bit Raspbian operation system with ARMv7 architecture. So you need to search only images that has ARM tag (not ARM 64). But Raspberry Pi has 64 bit processor, so it is possible to install Ubuntu Linux with ARMv8 instructions set. Ubuntu image can be downloaded from official Raspberry Pi site.
Install Docker Compose
Docker Compose make easier to run several containers on one machine. You can describe all container parameters and start all containers using single command
docker-compose up -d
To install docker compose first of all need to clone repository and choose the branch. Can take release branch or specific version branch
git clone https://github.com/docker/compose.git
cd compose
git checkout bump-1.23.2
Now run following command to modify install script
sed -i -e 's:^VENV=/code/.tox/py36:VENV=/code/.venv; python3 -m venv $VENV:' script/build/linux-entrypoint
sed -i -e '/requirements-build.txt/ i $VENV/bin/pip install -q -r requirements.txt' script/build/linux-entrypoint
After that execute command
docker build -t docker-compose:armhf -f Dockerfile.armhf .
docker run --rm --entrypoint="script/build/linux-entrypoint" -v $(pwd)/dist:/code/dist -v $(pwd)/.git:/code/.git "docker-compose:armhf"
sudo cp dist/docker-compose-Linux-armv7l /usr/local/bin/docker-compose
sudo chown root:root /usr/local/bin/docker-compose
sudo chmod 0755 /usr/local/bin/docker-compose
docker-compose version
It can take some time to compile - Raspberry Pi is not so powerful as usual desktop or notebook computers. If all was installed correctly you will see docker compose version that looks like this:
docker-compose version 1.23.2, build 1110ad01
docker-py version: 3.6.0
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.1.0j 20 Nov 2018
Conclusion
Your Raspberry Pi runs Docker and Docker Compose. Now can run several services on this server. Processor power will be enough to deploy several web applications - sites, blogs, cloud or NAS storage that will be used by small amount of users.