I am working on microsoft translator and api is not working inside container.
I am trying to set proxy server inside my docker container but it is not working I tried to run on PowerShell it works
[Environment]::SetEnvironmentVariable("HTTP_PROXY", "http://1.1.1.1:3128", [EnvironmentVariableTarget]::Machine)
[Environment]::SetEnvironmentVariable("HTTPS_PROXY", "http://1.1.1.1:3128", [EnvironmentVariableTarget]::Machine)
But when I tried to run same commands inside docker container it is not executing, it gave me error .
docker container exec -it microsofttranslator /bin/sh
ERROR
/bin/sh: 1: Syntax error: word unexpected (expecting ")")
4
Answers
There could be various reasons for it, Considering there is not much detail, I will point some of the common issues that might be there.
sh
however it might requirebash
. In such cases you might need to add/install bash in your dockerfile.dos2unix
on your files. If you are using windows, You can go through Notepad++, and ensure that Encoding isUTF-8
notUTF-8 BOM
And to run the docker container with proxy inside them. You can go through this solution.
How to configure docker container proxy?
This is one of the common issue which might be causing this, otherwise there could be many other reasons.
If you have a dockerfile, could you add these lines and give it a try
The error is because in your start script of docker container, your syntax cannot be executed by plain
sh
, you should usebash
instead.I have re-produced with a simple example.
So, try
docker container exec -it microsofttranslator /bin/bash
Should you need to pass proxy env variables , please read
this
you can easily set up a proxy for your specific container or for all containers just by using these two environmental variables
HTTP_PROXY
andHTTPS_PROXY
1. For spcific container
Proxy For specific container using
Dockerfile
:Proxy for specific container without defining them in
Dockerfile
:docker run -d -e HTTP_PROXY="http://1.1.1.1:3128" -e HTTPS_PROXY="http://1.1.1.1:3128" image:tag
2. For all containers
You to execute bellow mentioned commands:
Paste bellow mentioned content into the file and save it