Docker Community Forums

Share and learn in the Docker community.

CMD Command unwanted escaping of characters

I am trying to deploy my server to Heroku. Heroku has an environmental varriable $PORT that I am supposed to bind to my Swift server.

I tried to achieve this the following way:

CMD ["serve", "--env", "production", "--hostname", "", "--port", "$PORT"]

For some reason the didn’t work because the port had a ‘\’ character in front of it, like so:

serve --env production --hostname --port \35626

So I tried this to get rid of the first character of the PORT variable:

CMD ["serve", "--env", "production", "--hostname", "", "--port", "${PORT:1}"]

However on the Heroku servers this translated as

serve --env production --hostname --port \$\{PORT:1\}

I don’t understand why is the ${PORT:1} is escaped?

I found that it works best with a combination of both martineau’s answer and mastashake57’s answer.

set pwd=abc^&123
echo %pwd%
Still fails, and

set pwd=“abc&123”
echo %pwd%
Adds quotes to it (you can’t remove the quotes with a for loop or string manipultaion because it will fail again, thanks to the ampersand), which isn’t that great.


set “pwd=abc^&123”
echo %pwd%
Works perfectly.

Hope that helps.