Analytics | 3 min | 2030
Portainer is a management UI which allows you to easily manage your different Docker environments.
This is what I will try to accomplish in this tutorial. You will be able to:
- Run Portainer for Docker management on Windows, Linux and on a Cloud platform
- Start container with a predefined admin password, in case you are on a public network
If you are running Docker on Ubuntu or Mac OSX, you can start using Portainer as a Docker Container typing the following:
docker volume create portainer_data docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
The first line creates a Docker volume, where the Portainer configuration is saved, including the Portainer's admin password hash. That means, if you forgot your password, you can delete the volume and create a new one and Portainer will ask you for a new password again!
On Windows, when you install Docker, you have the chance to install Windows or Linux container type. I recommend Linux container -Docker also recommends that ;)-.
Option 1: If you are running Docker for Linux container type on Windows 10, follow this tutorial to deploy the Portainer container.
In case you have some problems with the setup on Windows, you can remove it typing the following on a Terminal/Powershell with administrator rights:
docker stop portainer docker rm portainer docker rmi portainer/portainer netsh interface portproxy reset netsh advfirewall firewall delete rule name="docker management"
Option 2: If you do not want to create a loopback (option 1) you can setup a tcp socket. To do that:
- Create a json file in
- Name that file
- Add the following to that file:
- Restart the Docker service
After doing that, you need to create the pass-through (inbound rule) on the Windows firewall (like option 1):
netsh advfirewall firewall add rule name="docker management" dir=in action=allow protocol=TCP localport=2375 enable=yes profile=domain,private,public
This needs to be allowed for all profiles, because the container virtual interface is detected as on a Public network. Then, run the Portainer container as usual with the following line:
docker run -d --restart always --name portainer -v portainer_data:/data portainer/portainer -p 9000:9000 portainer/portainer
On the Cloud / Public Networks
The first time that you run the Portainer container, it will ask you for an admin password. If you are on a public network, or if the people on your network are mad at you, you should run the container with a predefined admin password. Fortunatelly, Portainer allows this using an argument. But, you need the hash of your password. There are two ways to do that:
Option 1: If you have installed
htpasswdon your system, you can use this line:
htpasswd -nb -B admin <password> | cut -d ":" -f 2
Option 2: If your system does not provide
htpasswd, you can use a Docker container to calculate the hash typing the following line:
docker run --rm httpd:2.4-alpine htpasswd -nbB admin <password> | cut -d ":" -f 2
After getting the password-hash, you can start the container using:
docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer --admin-password '<password-hash>'
<password-hash>is what you got using Option 1 or 2 (yes, you have to use the ' ').
If you have to deploy Portainer as a Docker Swarm service, check this link for more information.
This small tutorial helps you to run a Portainer Container for Docker management. It presents some tricks to run it on Windows, and to predefine an admin password, if you are on e.g. a Cloud platform. I personally use Portainer a lot, it is an easy way to check what is running on the Docker engine, and the actual status and logs of the containers. You can also use the bash console to run some commands inside the containers.