How to install Docker on Raspberry Pi

How to install Docker on Raspberry Pi

Because the Raspberry Pi is based on ARM architecture, the installation and use of Docker are also different. There is a lot of content that needs to be discussed, so I will just pick it out here.

Raspberry Pi is based on ARM architecture, which is different from PC. So even if you can make some docker images on the Raspberry Pi, you can't run them on other PCs. Conversely, Docker images on other PCs cannot run on the Raspberry Pi.

If you need to find a Raspberry Pi-specific image, just search for ARM or Rpi on Dockerhub .

There is a warehouse called Hypriot that has made a lot of dockers specifically for Raspberry Pi, you can refer to it.

Raspberry Pi reference: Get Docker CE for Debian

Reference: My home server powered by Pi and Docker

The most difficult part of installing Docker on Raspberry Pi is to correctly select the source and add the GPG-key, so that you can find and download the appropriate version of Docker. This process is very cumbersome and it is difficult to have a unified solution.

Official version one-click installation script

Note: Many people say that the official one-click installation script is no longer supported. But the current position is actually still supportable.

Reference: The easy way to set up Docker on a Raspberry Pi

Before I start, let me explain: I have failed many times before and have found many related solutions but none of them worked. until. . .

It didn't work until I sudo apt-get update and most importantly sudo apt-get upgrade .

In fact, you can see during the upgrade that many system dependency packages have been updated, which solves all the problems that caused the previous unsuccessful Docker installation.

After the upgrade is completed, the formal installation begins:

You need to use a shell script, get.docker.com , and the entire website has only this one script. Download and execute:

$ curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh

When completed, it will display:

Then run hello world and try it out:

$ sudo docker run hello-world

Then it displays:

Manual Installation

Preparation:

#Install SSL related, let apt download via HTTPS:
sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common

# Add docker's GPG key
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
# Check if the key matches (9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88)
sudo apt-key fingerprint 0EBFCD88

#Add apt download source for docker sudo echo "\ndeb-src [arch=amd64] https://download.docker.com/linux/debian wheezy stable\n" >> /etc/apt/sources.list

#Update source sudo apt-get update

Install docker:

$ sudo apt-get install docker-ce

Execute docker without sudo

In order to avoid having to type sudo every time you execute docker , we need to create a user group for docker and grant permissions:

# Create the docker user group sudo groupadd docker

# Add the current user to the docker user group sudo gpasswd -a $USER docker

# Update the current user group changes (no need to log out and log in again)
newgrp docker

Install docker-compose

You can download and run docker compose as a docker container:

docker run \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v "$PWD:/rootfs/$PWD" \
  -w="/rootfs/$PWD" \
  docker/compose:1.13.0 up

# Set alias shortcuts (`~/.zshrc` or `~/.bash_profile`)
alias docker-compose="'"'docker run \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v "$PWD:/rootfs/$PWD" \
  -w="/rootfs/$PWD" \
  docker/compose:1.13.0'"'"

Common Errors

Python: No module name lsb_release

First check whether lsb_release is already installed on your machine, or reinstall it:

$ sudo apt-get install lsb-release

If you still have this problem, check your Python version. If it is python3, then it is likely that the version is insufficient, because lsb_release requires at least python3.5.
To solve this problem, just set the default python back to python2. It's just a matter of creating a shortcut with ln:

# Backup (the specific location of Python depends on your own situation)
$ sudo mv /usr/bin/python /usr/bin/python_bak

# Replace $ sudo ln -s /usr/bin/python2.7 /usr/bin/python

Then try $ lsb_release -cs again to see if jessie is displayed

無法添加源add-apt-repository 報錯找不到相關源

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Installation steps of docker-ce on Raspberry Pi 4b ubuntu19 server
  • How to install Docker and configure Alibaba Cloud Image Accelerator
  • How to view files in Docker image
  • How to use Docker buildx to build multi-platform images and push them to private repositories
  • Use the docker build kit to build a Docker image that can be used on the Raspberry Pi

<<:  React ref usage examples

>>:  MySQL 4G memory server configuration optimization

Recommend

Execution context and execution stack example explanation in JavaScript

JavaScript - Principles Series In daily developme...

Solution to 1045 error in mysql database

How to solve the problem of 1045 when the local d...

Vue uses echarts to draw an organizational chart

Yesterday, I wrote a blog about the circular prog...

js date and time formatting method example

js date time format Convert the date and time to ...

Solution to 1449 and 1045 exceptions when connecting to MySQL

Solution to 1449 and 1045 exceptions when connect...

A must-read career plan for web design practitioners

Original article, please indicate the author and ...

Learn Vue middleware pipeline in one article

Often when building a SPA, you will need to prote...

What I learned while building my own blog

<br />In one year of blogging, I have person...

Vue Element front-end application development to obtain back-end data

Table of contents Overview 1. Acquisition and pro...

jQuery plugin to implement search history

A jQuery plugin every day - to make search histor...