Aha, docker.
As localhost within docker means different than on the host, it will only work if you pass ip so when selenium open browser within docker it should be able to access moodle site.
Also, above will fail for scenarios with @_file_upload tag as the file doesn't exist within docker. To make @_file_upload pass you need to share moodle path within your selenium docker at same location.
FYI: https://github.com/rajeshtaneja/docker/ might help you running your tests using docker.