A Guide to Portainer Setup in Ubuntu Linux

A Guide to Portainer Setup in Ubuntu Linux

Portainer is an extremely useful tool for managing Docker containers, be it a WordPress stack, a reverse proxy or even a custom DNS server! This guide will go through setting up Portainer on Ubuntu and all the necessary networking required to do so.

Docker containers consist of runtimes that includes everything it needs – for example, for the official WordPress image, the container includes the Apache web server, and php, which are all needed to run WordPress standalone.

Portainer offers a GUI (Graphical User Interface) through a web interface, so you can start, reboot, stop and delete containers very easily. It also offers a very easy to use SSH client into the container, all inside the browser!

Prerequisites

  • An instance running Canonical Ubuntu 18.04 LTS or later (20.04 will work)
  • SSH access into the Ubuntu instance

Installing Docker and Docker-Compose

Install Docker and Docker-Compose

Update and Upgrade

Make sure that you’re running the latest version of Ubuntu.

sudo apt-get update && sudo apt-get upgrade

Install Docker

Now we’ll get onto the installation script, it’ll install Docker on your machine.

curl -sSL https://get.docker.com | sh

Install Docker-Compose

sudo apt-get install libffi-dev libssl-dev
sudo apt install python3-dev
sudo apt-get install -y python3 python3-pip

Sometimes you’ll get an error message “Package has no installation candidate”, and an easy way to fix this is to reset your repository: (this will first make a backup of your old repository file then recreate a default version of it)

sudo mv /etc/apt/sources.list ~/
sudo touch /etc/apt/sources.list

Once python and python-pip has been installed, you can go ahead and install docker-compose.

sudo pip3 install docker-compose

(Optional) Add Docker System Service to Start Containers at Boot

This is a good addition, you can run the script below to enable start-up for Docker containers during system boot – this can prevent lots of downtime as the WordPress container will simply start up again in the event of a forced reboot.

sudo systemctl enable docker

Test that Docker is Installed

First, run the following script to test that your Docker installation was successful.

docker run hello-world

If it worked, it’ll display the following output:

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (arm64v8)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

Installing Portainer

Create the Portainer volume

docker volume create portainer_data

Run the Portainer container:

docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

You should see the output below if it was successful:

latest: Pulling from portainer/portainer
d1e017099d17: Pull complete 
a7dca5b5a9e8: Pull complete 
Digest: sha256:4ae7f14330b56ffc8728e63d355bc4bc7381417fa45ba0597e5dd32682901080
Status: Downloaded newer image for portainer/portainer:latest
2fd5f4a0883a9d358ad424fd963699445be8839f3e6a2cf73d55778bcc268523

Opening Ports for Portainer

Then, open port 9000 to access your portainer instance, follow this guide if you’re on Oracle Cloud, or check out the links below for AWS and Azure.

How to Open Ports in Oracle Cloud

For AWS EC2

Follow these steps to do this:

  • Open “Network & Security” — Security Group settings are on the left-hand navigation
  • Find the security group connected to your instance
  • Choose “inbound rules
  • Type the port number (in your case 8787) in “port range” then click “Add Rule”
  • Use the drop-down and add HTTP (port 80)

And it is done.

From intellipaat.com/community/3700/how-to-open-..

For Microsoft Azure VMs

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/nsg-quickstart-portal

Final Setup with Portainer

Go to YOUR_SERVER_IP:9000 to set up Portainer. You’ll then be prompted to set up any username and passwords for the admin account, so keep these details! Then, you can manage your containers through a web interface!

Happy coding!

The post A Guide to Portainer Setup in Ubuntu Linux appeared first on Jiuyu's Guide.