3

On my first use of Docker Desktop on my Mac, I pulled MySQL from search bar (for Docker Hub presumably), and hit Run. A dialog appeared asking me for configuration options such as port number. I clicked Run to start the container.

I received an error message, saying:

You need to specify one of the following as an environment variable:
- MYSQL_ROOT_PASSWORD
- MYSQL_ALLOW_EMPTY_PASSWORD
- MYSQL_RANDOM_ROOT_PASSWORD

Unfortunately, being new to Docker in general and to Docker Desktop app specifically, I do not know how to set an environment variable after having already established this container within Docker Desktop app.

  • I cannot find a way back to that initial configuration dialog where I vaguely recall seeing options for setting environment variables.
  • I cannot find any other settings for my now-existing container.

How does one establish environment variables for an existing container within Docker Desktop?

4

2 Answers 2

3

Docker Desktop (or Docker for that matter) doesn't provide an option to add environment variable once your container is up and running, and any additions/changes to environment variables via the docker exec command are limited to that specific session.

I'd recommend you stop and run a new container again, specifically since the error happens when MySQL starts up.

You can set the environment variables when you click on the Images section and click "Run"

Images

Expand optional settings

Set environment variables

4
  • But then I would need to rewrite all the environment variables, correct? Is there any way to just add one to an already existing container configuration?
    – ch1ll
    Commented Aug 21, 2023 at 6:06
  • 2
    No, there's no such option
    – Sathyajith Bhat
    Commented Aug 23, 2023 at 8:37
  • @SathyajithBhat - what if the UI is not showing you the "Environment variables" section? Under optional settings, I only see ports and volumes... Commented Mar 7 at 18:43
  • @SathyajithBhat - looks like I had an old version of Docker Desktop (4.9). I updated and now the environment variable inputs are showing. Must have been a newer feature. Commented Mar 7 at 19:42
3

In docker desktop there's an option "copy docker run" which will regenerate the command used to run your container:
screenshot

Then it's easy to add an environment variable by adding --env=NewVaraiable=ItsValue . Just don't add to the end of the generated command since that would run that part as a command inside the new container.

1
  • Is there a way to modify this run command in the Docker Desktop interface? Or are you saying that this command needs to be copied to a text-editor, modified as required, and then pasted to a command prompt? Commented May 25 at 18:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .