Some advice I found a while back was to commit it for user-facing applications, where it’s more important that they get exactly the same behaviour you tested, but to leave it out for libraries, where the flexibility of dependency versions is more valuable.
That’s it! If you don’t specify a host path, i.e. the path before the colon, Docker will create an volume which saves any changes you make to that path in the container, but won’t mount any existing path from the host to the container.