The base image of the container make some tests and run code to "fix" something how is not a problem.
Like this:
version: '3.9'
services:
tor:
deploy:
replicas: 1
image: dperson/torproxy:latest
cap_drop:
- ALL
user: "tor:1999"
networks:
- tor-net
networks:
tor-net:
external:
name: tor-net
Something like this stack should work.
Maybe set the permissions only on the image and use chown only if the user is root.