1

I need to execute the next command:

az container create --resource-group myresourcegroup --name mycontainer --image myregistry.azurecr.io/myimage:latest --dns-name-label mysite --ports 80 --environment-variables 'SQLALCHEMY_DATABASE_URI'='postgresql://psql.postgres.database.azure.com:5432/postgres?user=myuser@psql&password=myPassword&sslmode=require'

I used this sample

But it fails due to PowerShell doesn't recognize the string after 'SQLALCHEMY_DATABASE_URI'= as string. It parses the last one as command arguments. I tried to pass environment variables as a dict @{'SQLALCHEMY_DATABASE_URI'='myconnectionstring'} but it didn't help.

What's a right way to make it?

Denis Sologub
  • 7,277
  • 11
  • 56
  • 123

1 Answers1

1

In PowerShell, do not try to compose a single string from multiple, possibly quoted, strings by direct adjoining - perhaps surprisingly, that won't work if the first string happens to be quoted, because it then becomes its own argument - see the bottom section of this answer for more information.

Instead, use:

  • either: a single quoted string (e.g., 'foo bar' or "foo $(Get-Date)")
  • or: an expression with + that synthesizes a string from verbatim and expandable (interpolating) strings, as needed (e.g., ('The value of $HOME is: ' + "$HOME.")

In your case, a single verbatim ('...') string[1] will do.

That is, instead of what you tried (which is passed as two arguments):

'SQLALCHEMY_DATABASE_URI'='postgresql://psql.postgres.database.azure.com:5432/postgres?user=myuser@psql&password=myPassword&sslmode=require'

pass (note that only overall '...' quoting is used):

'SQLALCHEMY_DATABASE_URI=postgresql://psql.postgres.database.azure.com:5432/postgres?user=myuser@psql&password=myPassword&sslmode=require'

[1] See the bottom section of this answer for an overview of string literals in PowerShell.

mklement0
  • 382,024
  • 64
  • 607
  • 775