Install Docker on Raspberry Pi with Ubuntu

Comments 0

Learn how to install Docker on a Raspberry Pi running Ubuntu Server Edition and deploy an Apache HTTP Server.

In this guide I’ll show you how to install Docker on a Raspberry Pi running Ubuntu Server Edition for a complete Docker portable. We’ll also deploy an Apache HTTP server, and I’ll give you some good resources to learn from.

FYI: Docker is an application that enables “containerized” apps similar to a virtual machine. Docker has an image repository of thousands of pre-configured applications like Apache HTTP server (which we’ll install later in this guide), Ubuntu, Python, Postgres, Node.js, and many others (I’ll give you links at the end of this tutorial).



Install Docker

Before we install Docker, let’s update the cache and upgrade software:

sudo apt update && sudo apt upgrade -y

Let’s install some required software that apt needs to upgrade packages over HTTPS:

sudo apt install curl ca-certificates apt-transport-https software-properties-common

Let’s add the Docker GPG key:

curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

And add the Docker repo to the sources.list file:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Let’s update the apt cache now that we have the Docker repo source:

sudo apt update

And install Docker community edition:

sudo apt install docker-ce -y

Let’s make sure everything went OK and Docker is installed and running:

sudo systemctl status docker
Check Docker status

Add User ‘pi’ to Docker Group

So that you don’t have to add sudo for Docker commands, we add user pi to the Docker group (we’re using the ${USER} variable to reference the current user pi):

sudo usermod -aG docker ${USER}

Then apply the changes by logging in and out (you’ll need to enter your password):

su - ${USER}

Let’s make sure your user was added to the Docker group:

groups ${USER}
Check if user pi belongs to the Docker group

Deploy ‘Hello World’ Container

Let’s deploy our first Docker container called “Hello World” which will display a greeting from Docker on the screen. First, we “pull” the image from the Docker repo:

docker pull hello-world

Then deploy the container:

docker run -it hello-world
Deploy Hello World

Deploy Apache HTTP Server Container

Now for something a little more serious, let’s deploy the Apache HTTP server container. First, let’s pull the image:

docker pull httpd

Let’s check that we have httpd and hello-world images available:

docker images
Check what Docker images are available

Now we deploy the httpd container. I will give an explanation of each option:

  • -d – Run in detached mode
  • --name – The name of the deployment, I have named it apache-httpd
  • -p – Map local computers port to Apaches port, in this case port 80 80:80
  • -d – Use the Apache image httpd
docker run -d --name apache-httpd -p 80:80 -d httpd

You should see the Apache container ID:

Apache container deployed

Let’s see if Apache is working. We need to find the IP address of your Raspberry Pi, enter the ip address command:

ip address
Run the IP Address command to see your Raspberry Pis IP address

Look for the eth0 interface which will show your RPi’s IP address. Enter the IP address into your web browser and hit ENTER (you may get a security warning, click Continue)

It Works!

If you get the default Apache test page “It Works!” then you’re good to go. To stop the Apache instance, use the following command:

docker stop apache-httpd


I hope you enjoyed this introduction to Docker on Raspberry Pi and if you want to learn more, look at the Further Reading section below and check out this Getting Started Guide. If you ran into any trouble, hit me up in the comments or socials/email and don’t forget to sign up to my newsletter for all the latest news and guides delivered to your inbox: Newsletter Sign Up.

Newsletter Signup

Privacy Policy

See Also

Further Reading

Categories Ubuntu, Apache


There are currently no comments on this article.


Enter your comment below. Fields marked * are required. You must preview your comment before submitting it.

PLEASE NOTE: You must preview a comment before submitting

Comments use Textile formatting