PhotoPrism is a web-based photo management application. It automatically detects objects, locations, and labels. It is a promising self-hosted Google Photos alternative. Photoprism can be installed on Docker as a container. In this tutorial we will install Photoprism on Docker and load an existing collection of photos.
Installing Photoprism Docker container
Make sure you have installed Portainer & Docker before proceeding. We will add a docker stack of PhotoPrism with MariaDB as a data store.
1. On Portainer, add a new stack with name PhotoPrism. Leave the Build method as Web Editor.
2. Copy the below compose file content into the Web editor. Do not deploy the stack yet, I’ll explain what each configuration does in the following steps. You can customize if needed.
---
version: '2'
services:
mariadb:
image: mariadb
container_name: mariadb
restart: unless-stopped
command: mysqld --transaction-isolation=READ-COMMITTED --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --max-connections=512 --innodb-rollback-on-timeout=OFF --innodb-lock-wait-timeout=50
volumes:
- "/opt/container/mariadb/storage:/var/lib/mysql"
environment:
MYSQL_ROOT_PASSWORD: changeme
MYSQL_DATABASE: photoprism
MYSQL_USER: photoprism
MYSQL_PASSWORD: changeme
network_mode: bridge
photoprism:
image: photoprism/photoprism:latest
container_name: photoprism
ports:
- 2342:2342
environment:
PHOTOPRISM_HTTP_PORT: 2342
PHOTOPRISM_ADMIN_PASSWORD: "changeme"
PHOTOPRISM_DATABASE_DRIVER: "mysql"
PHOTOPRISM_DATABASE_SERVER: "mariadb:3306"
PHOTOPRISM_DATABASE_NAME: "photoprism"
PHOTOPRISM_DATABASE_USER: "photoprism"
PHOTOPRISM_DATABASE_PASSWORD: "changeme"
PHOTOPRISM_SITE_URL: "http://localhost:2342/"
PHOTOPRISM_SITE_TITLE: "PhotoPrism"
PHOTOPRISM_SITE_CAPTION: "Browse Your Life"
volumes:
- "/opt/container/photoprism//import:/photoprism/import"
- "/opt/container/photoprism/storage:/photoprism/storage"
- "/mnt/share/photos:/photoprism/originals"
restart: unless-stopped
network_mode: bridge
MariaDB Database container
3. We will configure a DB store in MariaDB for PhotoPrism to use. Start with setting the listening port (default:3306) for the container.
4. Set a storage location for MariaDB application data.
5. Add a root password for mysql.
6. Create a user and database for PhotoPrism. We will use them again in the PhotoPrism settings.
PhotoPrism container
7. The default Container port is 2342 if you need change it at the two highlighted places (This is something I rarely do). This container port can be mapped onto a different host port, I set that also to 2342 here.
8. Now set your web UI administration password. As far as I know there is no user management in this version. You only have an admin user for access.
9. Next, add the mariadb connection info and user credentials we entered earlier in MariaDB.
10. You can set either an external or internal site URL using the PHOTOPRISM_SITE_URL variable. This will be used when you share the photos with others. I am not going to share this outside so I am leaving it as localhost.
11. Additionally, volumes are required to store imported images (/photoprism/import), and other metadata (/photoprism/storage)used by PhotoPrism container.
You can also add existing images under /photoprism/originals.
12. Deploy Stack once everything above is done, portainer will install two containers and start them.
13. Go to http://localhost:2342 on your browser, and login with the admin credentials you set earlier.
14. To load existing images you have to re-index the library. Go to Library, hit Start to initiate indexing.
You can re-index if you happen to add more files to the originals folder. If you upload or import via the interface it happens automatically.
That is it! PhotoPrism is ready and now you can view all your images under photos.
11 comments
Great guide, thanks so much. Only problem for me is when I try to deploy the stack it pops up a red message box saying “Deployment error. Unable to deploy stack” with no other explanations. Any help with this would be appreciated.
Thanks for commenting!
It is a generic error but make sure the “bridge” network exists. That’s the only situation I could think of causing an error.
thanks for many tutorials helping with the learning curve, Is it best to have separate mariadb containers for Photoprism and nextcloud? rather than sharing?
I think you can go either way. Although, some like the idea of a completely independent group of containers for ease of management. I would recommend going by your use case.
Thanks for this. Sorry for the noob question.
I get a failure on deployment that says there is a problem using the undefined network “bridge”. But this network does exist… What am I missing?
Kind of answered my own question… I was able to successfully get the container running by using network_mode:bridge, but that didn’t give me access to the containers from the host. By removing all network directives, the containers fell back to using the default bridge (https://netcraftsmen.com/docker-networking/#:~:text=By%20default%2C%20containers%20on%20a%20host%20all%20connect%20to%20the%20default%20bridge%20docker0%2C%20and%20all%20ports%20on%20them%20are%20exposed%20(published)%20to%20the%20outside%20world.) which worked for me.
Thank you so much! yours is the more correct solution for this. I am going to update my compose script accordingly.
When deploying I get photoprism constantly spitting out: dial tcp: lookup mariadb on 192.168.86.1:53: no such host
it’s a DNS thing, try replacing mariabc with the IP address of the docker server.
also, the compose file doesn’t list the mariadb ports. you need a new line that says
ports:
– 3306:3306
just like the one below for photoprism container.
I followed this guide to a T including adding the following port mapping as described in a prior comment
ports:
– 3306:3306
I’m trying to access photoprism at its host’s IP address and port, e.g. 192.xxx.xxx.xxx:2342, but i’m getting “error: connection refused”. Can’t seem to figure out where that error is happening. Other services running in other containers on the same docker host on different ports are responding as expected.
Additional detail: my logs reveal the following error which is probably a clue, but I can’t figure out how to fix it. My docker-compose is pretty much an exact copy paste of what was provided in this guide. :
time=”2023-01-04T20:37:00Z” level=error msg=”dial tcp: lookup mariadb on 9.9.9.9:53: no such host”
It’s almost like the two containers are on different networks or something, but both containers have the line “network_mode: bridge” as instructed above. The “bridge” network also exists in my configuration already so that’s not the issue.
Thanks in advance for any help!