One fix to this, albeit temporary, was to add a -E in the command. Like this
command: sudo -E docker-php-ext-install zip intl sodium pcntl bcmath
According to the man page this does this:
Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.