Bookmark

Run PhotoPrism in Docker with MariaDB and Persistent Photo Storage

PhotoPrism is a photo application that can tag and find pictures automatically and can run at home, on a private server, or in the cloud.[13] i12bretro tutorial 0902 runs PhotoPrism with MariaDB in Docker, persists storage and originals on the host, and exposes the web UI on port 2342.[13]

Youtube video player

The original tutorial video is linked on YouTube.[13]

1. Install Docker

  1. Log into the Linux device.[13]
  2. Run:[13]
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# install prerequisites
sudo apt install apt-transport-https ca-certificates git curl software-properties-common gnupg-agent -y
# add docker gpg key
curl -fsSL https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release)/gpg | sudo apt-key add -
# add docker software repository
sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release) $(lsb_release -cs) stable"
# install docker
sudo apt install docker-ce docker-compose containerd.io -y
# enable and start docker service
sudo systemctl enable docker && sudo systemctl start docker
# add the current user to the docker group
sudo usermod -aG docker $USER
# reauthenticate for the new group membership to take effect
su - $USER

Reauthenticate after the Docker group update.[13]

2. Create MariaDB and PhotoPrism

  1. Run the commands that create the directories, network, MariaDB, and PhotoPrism; set the password variables to unique secrets before running.[13]

Set unique database passwords before running. I use matching values for MariaDB and PhotoPrism:[13]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# create working directories
mkdir ~/docker/photoprism/{storage,originals} -p && mkdir ~/docker/mariadb -p
# set owner of working directories
sudo chown "$USER":"$USER" ~/docker -R
# create docker network
docker network create containers
# run the mariadb docker container
docker run -d --name mariadb -e MYSQL_ROOT_PASSWORD=CHANGE_ME_ROOT_PASSWORD -e MYSQL_USER=photoprism_rw -e MYSQL_PASSWORD=CHANGE_ME_DB_PASSWORD -e MYSQL_DATABASE=photoprism -v ~/docker/mariadb:/var/lib/mysql --network containers --restart=unless-stopped mariadb:latest
# run photoprism container
docker run -d --name=photoprism --security-opt seccomp=unconfined --security-opt apparmor=unconfined -p 2342:2342 -e PHOTOPRISM_UPLOAD_NSFW="true" -e PHOTOPRISM_ADMIN_PASSWORD="CHANGE_ME_ADMIN_PASSWORD" -e PHOTOPRISM_DATABASE_DRIVER="mysql" -e PHOTOPRISM_DATABASE_SERVER="mariadb:3306" -e PHOTOPRISM_DATABASE_NAME="photoprism" -e PHOTOPRISM_DATABASE_USER="photoprism_rw" -e PHOTOPRISM_DATABASE_PASSWORD="CHANGE_ME_DB_PASSWORD" -v ~/docker/photoprism/storage:/photoprism/storage -v ~/docker/photoprism/originals:/photoprism/originals --network containers --restart=unless-stopped photoprism/photoprism

Keep both host volumes: ~/docker/photoprism/storage for application data and ~/docker/photoprism/originals for originals.[13] mariadb:3306 is the service/port inside the containers network; the database does not need a host port.[13]

3. Open the UI and add photos

  1. Open http://DNSorIP:2342.[13]
  2. Log in as admin with the password set in PHOTOPRISM_ADMIN_PASSWORD.[13]
  3. Copy photos to ~/docker/photoprism/originals, or use the web UI upload function.[13]
  4. Confirm PhotoPrism displays the photos and the container remains running.[13]

Isolation and content warnings

The tutorial uses --security-opt seccomp=unconfined and --security-opt apparmor=unconfined; these relax sandboxing, so I keep them only when the image/workload requires them and do not expose the app directly to the Internet.[13] PHOTOPRISM_UPLOAD_NSFW="true" enables uploads of NSFW content according to the source variable; I set a separate policy for users, backups, and sharing.[13]

Replace every CHANGE_ME_* value before running, never commit a secret-filled .env, and do not reuse admin/database passwords between services.[13] Back up storage, originals, and the database volume before updating the image.[13] If a password changes after MariaDB initialization, verify the user/password rotation procedure instead of editing the command and blindly recreating containers.[13]

Original tutorial video: [watch it on YouTube]1.[13]

Source

Original source: [Run PhotoPrism - A Google Photos Alternative - In Docker]2, published/updated 2024-08-12.[13]

Sources

[13] https://i12bretro.github.io/tutorials/0902.html — Run PhotoPrism in Docker


  1. https://www.youtube.com/watch?v=R2T89oz0jTA — official i12bretro video. ↩︎

  2. https://i12bretro.github.io/tutorials/0902.html — Run PhotoPrism - A Google Photos Alternative - In Docker. ↩︎


0 Bình luận

Góp Ý / Bình Luận / Đánh giá