Search code examples
dockerdocker-desktop

How to set environment variable in docker desktop in windows?


I used command "docker pull mysql:5.7.28" which showed image and container correctly in docker desktop but when trying to run the container it showed exited and error was MYSQL_ROOT_PASSWORD required.

So I need to edit MYSQL_ROOT_PASSWORD in yaml file to resolve this issue. Now the problem is simple I have not used docker-compose file to setup the container and unable to find option in docker desktop to set up this variable.


Solution

  • You can set the environment variable when you run the container with docker run - see, e.g. "Start a mysql server instance" on https://hub.docker.com/_/mysql.

    An alternative would be to create a docker-compose.yml and set the environment variable there (the reference for what you can put in Compose files is here).

    There might be a way to set environment variables in Docker Desktop, but I don't use it, so I don't know. The documentation should tell you, though.