When it comes to managing docker on remote machines (or even on you daily machine), it it sometimes feels tiresome to remember all the docker commands and use them on day to day bases. Tools like portainer brings a life to the our daily activities which involves management of docker and containers and images and repositories. The focus of this post will not be the advance learning of Portainer, but sort of its setup and introduction of portainer basic capabilities.
Installation
If you go to official site you will see many ways a portainer can be installed. Since we are using the setup we have created in my previous post, we will use the standalone installation as Install Portainer with Docker on Linux. You will see the command listed over there to install the portainer as a docker container with in docker. That’s great … right? But wait, what we will do before that is create a volume and a network MANUALLY (I know we need portainer to get rid of all this hassle, but believe me there will all hassle free once our manual initial setup is complete). Just follow my lead and you will see that easy life.
So lets create a network by executing the below command.
$ docker network create learn-docker
this network will now have the ip range, from which we can choose an IP to be assigned to our container. While running the container, if we don’t specify the Network and IP address, then docker will use the default bridge network and next available IP address from the range in that network. Let’s figure out what IP range.
$ docker inspect learn-docker
it will give output something like this
[ { "Name": "learn-docker", "Id": "97c7497ce58b152145075c9b136769cd9ab9594a7925611a92dadcc938a1d571", "Created": "2022-09-02T10:50:50.780728238+05:30", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": {}, "Config": [ { "Subnet": "172.18.0.0/16", "Gateway": "172.18.0.1" } ] }, "Internal": false, "Attachable": false, "Ingress": false, "ConfigFrom": { "Network": "" }, "ConfigOnly": false, "Containers": {}, "Options": {}, "Labels": {} } ]
Notice the Subnet
and Gateway
properties in the output above. By this configuration any container joining in that network will get an IP from range 172.18.0.2
and 172.18.255.255
.
Let’s move ahead and add a new volume for portainer by executing the following command.
$ docker volume create portainer_data
Now we are ready to install portainer. Execute the below command to install portainer.
$ docker run -d -p 8000:8000 -p 9000:9000 --network=learn-docker --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
By this time if you have started following the official documentation, you will notice that there they are using / exposing port 9443 in place of 9000. Please don’t bother that, as in future we will not expose that port from portainer anymore.
If the command was successful, you will see a nice long ID like string in console. Lets see the status of the portainer container by running following command.
$ docker ps
If the portainer is successfully installed and running, you will see that entry in the output there.
Open a browser window and navigate to http://localhost:9000. You should see screen to create your first admin user like below. Create your credentials and remember them / save them for the future use.
In case you see the screen something like below, just restart your portainer container by issuing the below command and refresh the page.
$ docker container restart portainer
On successful admin user creation you will be presented with a screen similar to below, from where we start our next section of configuration.