2020-04-09 22:52:11 +00:00
|
|
|
# Portainer in docker
|
|
|
|
|
|
|
|
###### guide by example
|
|
|
|
|
2020-04-25 23:48:23 +00:00
|
|
|
![logo](https://i.imgur.com/QxnuB1g.png)
|
2020-04-09 22:52:11 +00:00
|
|
|
|
2020-04-25 23:48:23 +00:00
|
|
|
# Purpose
|
2020-04-09 22:52:11 +00:00
|
|
|
|
2020-05-10 21:48:51 +00:00
|
|
|
Web UI for overview and management of docker environment.
|
2020-05-10 13:32:38 +00:00
|
|
|
|
|
|
|
* [Official site](https://www.portainer.io)
|
|
|
|
* [Github](https://github.com/portainer/portainer)
|
|
|
|
* [DockerHub image used](https://hub.docker.com/r/portainer/portainer/)
|
|
|
|
|
|
|
|
Portainer is a lightweight management web UI, that allows to easily manage
|
2020-05-10 15:06:37 +00:00
|
|
|
docker containers, networks, volumes, images,... the work.
|
2020-05-10 13:32:38 +00:00
|
|
|
|
|
|
|
In my use it is mostly information tool, rather than a management tool.
|
2020-04-09 22:52:11 +00:00
|
|
|
|
2020-04-25 23:48:23 +00:00
|
|
|
# Files and directory structure
|
|
|
|
|
|
|
|
```
|
2020-05-01 09:38:43 +00:00
|
|
|
/home/
|
|
|
|
└── ~/
|
|
|
|
└── docker/
|
|
|
|
└── portainer/
|
2020-05-10 13:32:38 +00:00
|
|
|
├── portainer-data/
|
2020-05-01 09:38:43 +00:00
|
|
|
├── .env
|
|
|
|
└── docker-compose.yml
|
2020-04-25 23:48:23 +00:00
|
|
|
```
|
|
|
|
|
2020-05-10 13:32:38 +00:00
|
|
|
* `portainer-data/` - a directory where portainer stores its peristent data
|
|
|
|
* `.env` - a file containing environmental variables for docker compose
|
|
|
|
* `docker-compose.yml` - a docker compose file, telling docker
|
|
|
|
how to build the containers
|
|
|
|
|
|
|
|
You only need to provide the files.</br>
|
|
|
|
The directory is created by docker compose on the first run.
|
|
|
|
|
2020-04-25 23:48:23 +00:00
|
|
|
# docker-compose
|
|
|
|
|
|
|
|
`docker-compose.yml`
|
|
|
|
```yml
|
|
|
|
version: '2'
|
|
|
|
|
|
|
|
services:
|
|
|
|
portainer:
|
|
|
|
image: portainer/portainer
|
|
|
|
container_name: portainer
|
|
|
|
hostname: portainer
|
|
|
|
command: -H unix:///var/run/docker.sock
|
|
|
|
restart: unless-stopped
|
2020-04-26 00:43:30 +00:00
|
|
|
env_file: .env
|
2020-04-25 23:48:23 +00:00
|
|
|
volumes:
|
|
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
2020-05-10 13:32:38 +00:00
|
|
|
- ./portainer-data:/data
|
2020-04-25 23:48:23 +00:00
|
|
|
|
|
|
|
networks:
|
|
|
|
default:
|
|
|
|
external:
|
|
|
|
name: $DEFAULT_NETWORK
|
|
|
|
```
|
|
|
|
|
|
|
|
`.env`
|
|
|
|
```bash
|
|
|
|
# GENERAL
|
2020-05-16 13:18:21 +00:00
|
|
|
MY_DOMAIN=example.com
|
2020-04-25 23:48:23 +00:00
|
|
|
DEFAULT_NETWORK=caddy_net
|
2020-05-02 20:48:23 +00:00
|
|
|
TZ=Europe/Bratislava
|
2020-04-25 23:48:23 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
# reverse proxy
|
|
|
|
|
2020-05-01 09:51:20 +00:00
|
|
|
Caddy v2 is used, details
|
|
|
|
[here](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/caddy_v2).</br>
|
2020-04-25 23:48:23 +00:00
|
|
|
|
|
|
|
`Caddyfile`
|
|
|
|
```
|
|
|
|
portainer.{$MY_DOMAIN} {
|
|
|
|
reverse_proxy portainer:9000
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
# Update
|
|
|
|
|
2020-05-10 13:32:38 +00:00
|
|
|
[Watchtower](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/watchtower)
|
|
|
|
updates the image automatically.
|
|
|
|
|
|
|
|
Manual image update:
|
|
|
|
|
|
|
|
- `docker-compose pull`</br>
|
|
|
|
- `docker-compose up -d`</br>
|
|
|
|
- `docker image prune`
|
|
|
|
|
|
|
|
# Backup and restore
|
|
|
|
|
|
|
|
#### Backup
|
|
|
|
|
|
|
|
Using [borg](https://github.com/DoTheEvo/selfhosted-apps-docker/tree/master/borg_backup)
|
|
|
|
that makes daily snapshot of the entire directory.
|
|
|
|
|
|
|
|
#### Restore
|
2020-04-25 23:48:23 +00:00
|
|
|
|
2020-05-10 15:06:37 +00:00
|
|
|
* down the portainer container `docker-compose down`</br>
|
|
|
|
* delete the entire portainer directory</br>
|
|
|
|
* from the backup copy back the portainer directory</br>
|
|
|
|
* start the container `docker-compose up -d`
|