We use the below code for unit testing the services that talk to a database system.
https://sergiocarracedo.es/integration-tests-in-golang-with-dockertest/
MySQL root password is hardcoded in the particular line and creates security issues. Is there any way we can pass that as env variable or docker secret ?
resource, err := pool.Run("mysql", "5.7", []string{"MYSQL_ROOT_PASSWORD=secret"})
CodePudding user response:
You can use the environment variable.
- First of all, get the env variable via
os.Getenv()
in your code
mysqlPwd := os.Getenv("MYSQL_ROOT_PASSWORD")
- Then run the docker with the
-e
option
docker run -e MYSQL_ROOT_PASSWORD=secret