Skip to content

Permission denied issues with mysql data and mounted (docker) volume #3946

Open

Description

Describe the bug

I recently tried re-creating my WCPay docker environment from scratch, and I hit an issue. The MySQL / db container had permissions issues with the data volume.

In our current docker environment, the data volume is a mounted folder (from the host OS). I think this causes the permission issue I'm seeing (maybe intermittent?).

There's a workaround – map user in compose file, so the container user has enough access.

I'd recommend switching to a named volume, which avoids the permissions issue altogether. This may also have other benefits since it's completely isolated inside the container. Note named volumes still persist across container recreate, so we still have a persistent database (and can reset it at will by deleting the volume - docker compose down --volumes).

I notice that we use a mounted volume for WordPress as well. I personally don't need this, perhaps if we move to a named volume it will simplify things and maybe even help with performance.

My understanding is that mounted volumes are best for sharing source code and config files into a container; not sure about using them to share large amounts of data "out".

Note if we do switch to named volumes, developers can easily override this if they have different needs, using docker-compose.override.yml. For example, if a developer needs to hack on WordPress core at the same time, they could clone locally and map into the container.

To Reproduce

  • Clone repo.
  • Put stuff in ./docker/data or remove write permissions (to force the issue!).
  • npm install
  • npm run up:recreate

Actual behavior

Lots of errors in database container like the following, and then it bails. No database container, unhappy WordPress.

woocommerce_payments_mysql | chown: changing ownership of '/var/lib/mysql/': Permission denied
woocommerce_payments_mysql | chown: changing ownership of '/var/lib/mysql/ibdata1': Permission denied
woocommerce_payments_mysql | chown: changing ownership of '/var/lib/mysql/wcpay_tests': Permission denied
woocommerce_payments_mysql | chown: changing ownership of '/var/lib/mysql/wcpay_tests/wptests_wc_product_meta_lookup.frm': Permission denied

Expected behavior

  • Quick and robust launch or recreate of dev env under a wide range of circumstances. (I believe using named volumes will make the env more reliable.)

Desktop (please complete the following information):

  • macOS Monterey, Intel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    category: devopsFeatures and tools supporting dev process.focus: devopsRelease processes, monitoring, automations, dev tools, CI/CD pipelinepriority: lowThe issue/PR is low priority—not many people are affected or there’s a workaround, etc.type: enhancementThe issue is a request for an enhancement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions