This page looks best with JavaScript enabled

Manage Docker Environment on VPS with your Local Portainer

 ·   ·  ☕ 2 min read

Introduction

In last post we learned to install and configure Portainer to maintain your local Docker environment. Although I’m not against command line, Portainer is a great companion if you don’t prefer to remember long commands to manager your docker. In this post I’m going to extend on last post and show how can you manage your VPS docker environment from your local Portainer installation.

Prerequisites

  • Portainer configured on your local machine

If you don’t have portainer configured on your local machine, please read my last post regarding installing and configuring Portainer on local machine.

Install Portainer Agent on your VPS

Well, this post is even shorter than the last one. Just make sure you are ssh’ed into your VPS and run Portainer Agent with the following command:

docker run -d -p 9001:9001 --name portainer_agent --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker/volumes:/var/lib/docker/volumes portainer/agent:latest

This command is very similar to the one we used for installing the Portainer server. What extra we are doing is we are also binding /var/lib/docker/volumes inside the container. The second difference is that this time we are using the portainer/agent image rather than portainer/portainer-ce.

Note:

  1. Although the installation is finished. You also need to expose port 9001 of your VPS so that you can connect to it over TCP. For example, I am using AWS and I have created a new security group and allowed only my home IP to connect to it.

  2. If your VPS OS has some OS level firewall, please allow port 9001 to open as well.

Configure Portainer Agent on your local system

We are back to our local installation. Here are the steps your should follow to add a new environment.

  1. From the sidebar, choose Environments. On the screen which appears, click on Add environment button.
  2. You shall see something like this:
Portainer add agent environment screen
Portainer add agent environment screen

The first field Name is for identification purpose among multiple environment. You can keep this anything you want.

Second one is Environment URL, here you need to put public IP of your VPS appended by :9001.

When you are done with it. Click on Add environment.

Now when you visit the home screen. You’d see both the environment listed to you.

Two Portainer environment added
Two Portainer environment added

Conclusion

This was a quick post I wanted to share. I hope it was helpful to you. If you like this post, please subscribe to the newsletter, connect with me on LinkedIn and follow me on Twitter.

Share on

Santosh Kumar
WRITTEN BY
Santosh Kumar
Santosh is a Software Developer currently working with NuNet as a Full Stack Developer.