How to replace env variable in docker at runtime?

  docker, question

InDockerfileA is defined inenvVariables, as follows:

...
 ENV MY_ENV dev
 CMD ["pm2","start", "pm2.json"," --env ${MY_ENV}","--no-daemon"]
 
 ...

Want to be in the mirrorRUNWhen, putenvReplace the variable with the specified one and write as follows:

docker run -e "MY_ENV=staging"  --name pm2_test -p 3500:3500  -d  pm2_test:v1

Q: Why do variables not work?

To do this

CMD pm2 start pm2.json --env ${MY_ENV} --no-daemon