[GH-ISSUE #78] Automate proxy configuration inside Android Emulator #61

Closed
opened 2026-03-01 15:39:48 +03:00 by kerem · 25 comments
Owner

Originally created by @Kurisutian on GitHub (Jun 12, 2018).
Original GitHub issue: https://github.com/budtmo/docker-android/issues/78

Operating System:
Debian 8

Docker Image:
butomo1989/docker-android-x86-7.1.1

Docker Version:
17.12.1-ce

Docker Command to start docker-android:
Running everything through Rancher

Expected Behavior

I'm running all emulators behind our corporate proxy.
When entering this as "HTTP_PROXY" and "HTTPS_PROXY" as well as different values for "NO_PROXY" I thought I can access everything from the emulator(s) like I would with other containers for automated testing (Desktop Browser Nodes from Selenium). It should work similar.

Actual Behavior

When entering the proxy information from our company, I can access websites using curl within the container but the android emulator does not open these very same sites (checked with www.google.de). Instead of showing me any site in the "device" I cannot get any outside connection.
Checked this with the bridge IP as well as our corporate proxy, nothing worked so far.

Originally created by @Kurisutian on GitHub (Jun 12, 2018). Original GitHub issue: https://github.com/budtmo/docker-android/issues/78 Operating System: Debian 8 Docker Image: butomo1989/docker-android-x86-7.1.1 Docker Version: 17.12.1-ce Docker Command to start docker-android: Running everything through Rancher ## Expected Behavior I'm running all emulators behind our corporate proxy. When entering this as "HTTP_PROXY" and "HTTPS_PROXY" as well as different values for "NO_PROXY" I thought I can access everything from the emulator(s) like I would with other containers for automated testing (Desktop Browser Nodes from Selenium). It should work similar. ## Actual Behavior When entering the proxy information from our company, I can access websites using curl within the container but the android emulator does not open these very same sites (checked with www.google.de). Instead of showing me any site in the "device" I cannot get any outside connection. Checked this with the bridge IP as well as our corporate proxy, nothing worked so far.
kerem 2026-03-01 15:39:48 +03:00
Author
Owner

@budtmo commented on GitHub (Jul 5, 2018):

Hi @Kurisutian ,

you can set up the proxy inside emulator manually. I just tested this article and it works. I am not sure if we can automate it by using adb command. :(

It would be great if you can help to investigate it @Kurisutian

<!-- gh-comment-id:402729287 --> @budtmo commented on GitHub (Jul 5, 2018): Hi @Kurisutian , you can set up the proxy inside emulator manually. I just tested t[his article](https://stackoverflow.com/questions/1570627/how-to-setup-android-emulator-proxy-settings) and it works. I am not sure if we can automate it by using adb command. :( It would be great if you can help to investigate it @Kurisutian
Author
Owner

@Kurisutian commented on GitHub (Jul 5, 2018):

Hi @butomo1989 ,
thanks for your reply. The problem I have with the manual config is, we intend to run a couple of these containers (>40) for automated testing and manually doing that is just to much of a hassle. We might scale up and down as well so we need to do it automatically.
Also I noticed when running the containers after a while there are so many defuntc adb processes that the container will take down the complete docker daemon on the host running. Did you ever experience something like that? It happened all the time so we needed to stop using the containers for now to prevent the host going down with other containers running on it as well.
If there is anything I can do to help investigate, let me know and I can do my best to support. Thanks!

<!-- gh-comment-id:402764272 --> @Kurisutian commented on GitHub (Jul 5, 2018): Hi @butomo1989 , thanks for your reply. The problem I have with the manual config is, we intend to run a couple of these containers (>40) for automated testing and manually doing that is just to much of a hassle. We might scale up and down as well so we need to do it automatically. Also I noticed when running the containers after a while there are so many defuntc adb processes that the container will take down the complete docker daemon on the host running. Did you ever experience something like that? It happened all the time so we needed to stop using the containers for now to prevent the host going down with other containers running on it as well. If there is anything I can do to help investigate, let me know and I can do my best to support. Thanks!
Author
Owner

@JoeSSS commented on GitHub (Jul 5, 2018):

Also I noticed when running the containers after a while there are so many defuntc adb processes that the container will take down the complete docker daemon on the host running.

I experienced it, that's why I limit the container to max 30 minutes and then destroy it

<!-- gh-comment-id:402764924 --> @JoeSSS commented on GitHub (Jul 5, 2018): > Also I noticed when running the containers after a while there are so many defuntc adb processes that the container will take down the complete docker daemon on the host running. I experienced it, that's why I limit the container to max 30 minutes and then destroy it
Author
Owner

@budtmo commented on GitHub (Jul 5, 2018):

Hi @Kurisutian @JoeSSS ,

I assume the topic that you guys discussed is not related with proxy, isnt it? It would be great if you open new issue for it, give some description and work around. To be honest I do not experience it because I do run many containers for now. :(

<!-- gh-comment-id:402767736 --> @budtmo commented on GitHub (Jul 5, 2018): Hi @Kurisutian @JoeSSS , I assume the topic that you guys discussed is not related with proxy, isnt it? It would be great if you open new issue for it, give some description and work around. To be honest I do not experience it because I do run many containers for now. :(
Author
Owner

@Kurisutian commented on GitHub (Jul 6, 2018):

I opened a new issue for that at https://github.com/butomo1989/docker-android/issues/86

<!-- gh-comment-id:402947365 --> @Kurisutian commented on GitHub (Jul 6, 2018): I opened a new issue for that at https://github.com/butomo1989/docker-android/issues/86
Author
Owner

@budtmo commented on GitHub (Jul 6, 2018):

For this issue, it is possible by passing flag -http-proxy

<!-- gh-comment-id:402960808 --> @budtmo commented on GitHub (Jul 6, 2018): For this issue, it is possible by passing flag -http-proxy
Author
Owner

@Kurisutian commented on GitHub (Jul 6, 2018):

Where would the be passed exactly?

<!-- gh-comment-id:402961196 --> @Kurisutian commented on GitHub (Jul 6, 2018): Where would the be passed exactly?
Author
Owner

@budtmo commented on GitHub (Jul 6, 2018):

@Kurisutian it should be pass in the line. Could you help me to solve this issue? we can do something like: we activate that proxy flag automatically if the http_proxy is set in environment variable.

<!-- gh-comment-id:402965067 --> @budtmo commented on GitHub (Jul 6, 2018): @Kurisutian it should be pass in the [line](https://github.com/butomo1989/docker-android/blob/master/src/app.py#L196). Could you help me to solve this issue? we can do something like: we activate that proxy flag automatically if the http_proxy is set in environment variable.
Author
Owner

@Kurisutian commented on GitHub (Jul 6, 2018):

This would actually be the expected behavior. If I explicitly set the http(s) and noproxy variables in the environment, it is because everything in the container needs to respect that. Right now if I enter a console from the UI in that the proxy will be used but in the emulator it's not. This inconsistency does not make much sense, since I wanted to use the proxy by setting it as an environment variable anyway.
So yes, I think this would be by far the better behavior to have the emulator use the proxy that has been set as an variable in the environment to remain this kind of consistency.

<!-- gh-comment-id:402967814 --> @Kurisutian commented on GitHub (Jul 6, 2018): This would actually be the expected behavior. If I explicitly set the http(s) and noproxy variables in the environment, it is because everything in the container needs to respect that. Right now if I enter a console from the UI in that the proxy will be used but in the emulator it's not. This inconsistency does not make much sense, since I wanted to use the proxy by setting it as an environment variable anyway. So yes, I think this would be by far the better behavior to have the emulator use the proxy that has been set as an variable in the environment to remain this kind of consistency.
Author
Owner

@Kurisutian commented on GitHub (Jul 11, 2018):

@butomo1989
What can I do to help exactly? Your suggestion to activate the proxy flag automatically seems like what should be used. Especially when we start up 40+ containers for parallel testing, setting the proxy manually is not an option. ;)

<!-- gh-comment-id:404066069 --> @Kurisutian commented on GitHub (Jul 11, 2018): @butomo1989 What can I do to help exactly? Your suggestion to activate the proxy flag automatically seems like what should be used. Especially when we start up 40+ containers for parallel testing, setting the proxy manually is not an option. ;)
Author
Owner

@budtmo commented on GitHub (Jul 11, 2018):

It would be great if you can help to fix it and create a PR, because I am working on something else currently @Kurisutian

<!-- gh-comment-id:404067852 --> @budtmo commented on GitHub (Jul 11, 2018): It would be great if you can help to fix it and create a PR, because I am working on something else currently @Kurisutian
Author
Owner

@mgrazioli commented on GitHub (Aug 6, 2018):

Hi,

I have also the same problem for setting up the proxy automatically when the emulator starts. I have tried to set http_proxy & https_proxy env inside docker container but i didn't have nothing results: Emulator doesn't take this setup.

I have also tried to set up manualy the proxy but I have noticed that only proxy with authentication work correctly.

Have you some idea for solving this big issue. Please help me.

I need to set up my proxy in automatic mode without authentication.

Thanks
Marco

<!-- gh-comment-id:410697767 --> @mgrazioli commented on GitHub (Aug 6, 2018): Hi, I have also the same problem for setting up the proxy automatically when the emulator starts. I have tried to set http_proxy & https_proxy env inside docker container but i didn't have nothing results: Emulator doesn't take this setup. I have also tried to set up manualy the proxy but I have noticed that only proxy with authentication work correctly. Have you some idea for solving this big issue. Please help me. I need to set up my proxy in automatic mode without authentication. Thanks Marco
Author
Owner

@budtmo commented on GitHub (Aug 8, 2018):

have you tried -http-proxy while running emulator command? @mgrazioli

<!-- gh-comment-id:411381750 --> @budtmo commented on GitHub (Aug 8, 2018): have you tried -http-proxy while running emulator command? @mgrazioli
Author
Owner

@mgrazioli commented on GitHub (Aug 8, 2018):

Hi Budi,
where do I put this command? I can not find file where is run emulator command

Thanks
Marco

<!-- gh-comment-id:411383593 --> @mgrazioli commented on GitHub (Aug 8, 2018): Hi Budi, where do I put this command? I can not find file where is run emulator command Thanks Marco
Author
Owner

@budtmo commented on GitHub (Aug 8, 2018):

@mgrazioli https://github.com/butomo1989/docker-android/blob/master/src/app.py#L214 could you create PR if it work.

<!-- gh-comment-id:411384349 --> @budtmo commented on GitHub (Aug 8, 2018): @mgrazioli https://github.com/butomo1989/docker-android/blob/master/src/app.py#L214 could you create PR if it work.
Author
Owner

@mgrazioli commented on GitHub (Aug 8, 2018):

Thankyou very much. I will try :-)

<!-- gh-comment-id:411384798 --> @mgrazioli commented on GitHub (Aug 8, 2018): Thankyou very much. I will try :-)
Author
Owner

@mgrazioli commented on GitHub (Aug 8, 2018):

Hi Budi,

when I insert -http-proxy in the command emulator, this doesn't run anymore. :-(

<!-- gh-comment-id:411394414 --> @mgrazioli commented on GitHub (Aug 8, 2018): Hi Budi, when I insert -http-proxy in the command emulator, this doesn't run anymore. :-(
Author
Owner

@mgrazioli commented on GitHub (Aug 8, 2018):

Hi Budi,
now emulator run, but -http-proxy option seems does not work correctly

<!-- gh-comment-id:411398175 --> @mgrazioli commented on GitHub (Aug 8, 2018): Hi Budi, now emulator run, but -http-proxy option seems does not work correctly
Author
Owner

@pawelus commented on GitHub (Aug 31, 2018):

@butomo1989 I tried to add the proxy setting in app.py but then emulator wouldn't start properly. It might be because I had to modify Emulator_x86 file to support building the image on a machine with proxy set (e.g. to download needed dependencies over proxy).

Is there some better way to build the image on a machine with proxy (e.g. by passing proxy as a build argument)?

<!-- gh-comment-id:417658633 --> @pawelus commented on GitHub (Aug 31, 2018): @butomo1989 I tried to add the proxy setting in app.py but then emulator wouldn't start properly. It might be because I had to modify Emulator_x86 file to support building the image on a machine with proxy set (e.g. to download needed dependencies over proxy). Is there some better way to build the image on a machine with proxy (e.g. by passing proxy as a build argument)?
Author
Owner

@eyal919 commented on GitHub (Mar 11, 2019):

anyone? any solutions for the proxy?

<!-- gh-comment-id:471531672 --> @eyal919 commented on GitHub (Mar 11, 2019): anyone? any solutions for the proxy?
Author
Owner

@kbalakumar99 commented on GitHub (Mar 21, 2019):

If emulator is launched using appium driver. Use avdArgs capability

capabilities.setCapability(AndroidMobileCapabilityType.AVD_ARGS, "-no-boot-anim -no-window -no-audio -http-proxy your-proxy-ip:3128");
p.s don't add http:// before your ip

Same case if launched manually,

emulator -avd emulator_name -no-boot-anim -no-window -no-audio -http-proxy your-proxy-ip:3128

<!-- gh-comment-id:475122524 --> @kbalakumar99 commented on GitHub (Mar 21, 2019): If emulator is launched using appium driver. Use avdArgs capability capabilities.setCapability(AndroidMobileCapabilityType.AVD_ARGS, "-no-boot-anim -no-window -no-audio -http-proxy your-proxy-ip:3128"); p.s don't add http:// before your ip Same case if launched manually, emulator -avd emulator_name -no-boot-anim -no-window -no-audio -http-proxy your-proxy-ip:3128
Author
Owner

@budtmo commented on GitHub (Mar 21, 2019):

you need to do 2 things:

  1. Enable the proxy to the container
  2. Enable the proxy to the emulator inside the container through custom arguments

@kbalakumar99 do you want to be part of this project as contributor by updating the document? it would be great

<!-- gh-comment-id:475159393 --> @budtmo commented on GitHub (Mar 21, 2019): you need to do 2 things: 1. Enable the proxy to the container 2. Enable the proxy to the emulator inside the container through [custom arguments](https://github.com/budtmo/docker-android/blob/master/README_CUSTOM_CONFIG.md#custom-emulator-arguments) @kbalakumar99 do you want to be part of this project as contributor by updating the document? it would be great
Author
Owner

@kbalakumar99 commented on GitHub (Mar 21, 2019):

@budtmo Thanks for your Invite. Yes, I am willing to contribute.

<!-- gh-comment-id:475160667 --> @kbalakumar99 commented on GitHub (Mar 21, 2019): @budtmo Thanks for your Invite. Yes, I am willing to contribute.
Author
Owner

@HasBert commented on GitHub (May 7, 2019):

Hey guys,
in my setup I'm using the emulator to spy apps with mitmproxy, which is in the same docker network as the emulator is.
I've read on the official mitmproxy site, that some android apps can bypass the http-proxy. I found this post from 2014! and I'm wondering if this issue also applies to the emulator, if I start it with EMULATOR_ARGS="-http-proxy 172.17.0.2:8080". So far it's working for me, I have no problems to spy on apps. Anyways I question myself:

  1. Is the EMULATOR_ARGS="-http-proxy 172.17.0.2:8080" attached globally or is there a way for apps to bypass?

The next question has more to do with basic understanding and the asked question above.
@budtmo You said we need to do 2 things to get the proxy to work. Apply the proxy to the container itself and second to the emulator as I did it.

  1. By attaching to the container you meant this? By attaching to the emulator, you meant to attach it to the bridge network gateway ip address? So in my case 172.17.0.1:8080?

  2. If I run the emulator in a separate docker bridge network (docker network create some-network), the official documentation says that this network is isolated to the outside world, so why can I browse websites with the emulator? Is it because of the --privileged option which gives the emulator the rights to communicate to the outside world?

Thank you for your time ;-) great work so far :-*

<!-- gh-comment-id:490285618 --> @HasBert commented on GitHub (May 7, 2019): Hey guys, in my setup I'm using the emulator to spy apps with [mitmproxy](https://hub.docker.com/r/mitmproxy/mitmproxy), which is in the same docker network as the emulator is. I've read on the [official mitmproxy site](https://docs.mitmproxy.org/stable/concepts-modes/), that some android apps can bypass the http-proxy. I found [this post](https://stackoverflow.com/questions/24417242/do-android-proxy-settings-apply-to-all-apps-on-the-device) from 2014! and I'm wondering if this issue also applies to the emulator, if I start it with `EMULATOR_ARGS="-http-proxy 172.17.0.2:8080"`. So far it's working for me, I have no problems to spy on apps. Anyways I question myself: 1. Is the `EMULATOR_ARGS="-http-proxy 172.17.0.2:8080"` attached globally or is there a way for apps to bypass? The next question has more to do with basic understanding and the asked question above. @budtmo You said we need to do 2 things to get the proxy to work. Apply the proxy to the container itself and second to the emulator as I did it. 2. By attaching to the container you meant [this](https://docs.docker.com/network/proxy/)? By attaching to the emulator, you meant to attach it to the bridge network gateway ip address? So in my case `172.17.0.1:8080`? 3. If I run the emulator in a separate docker `bridge` network (`docker network create some-network`), the [official documentation](https://docs.docker.com/network/bridge/) says that this network is isolated to the outside world, so why can I browse websites with the emulator? Is it because of the `--privileged` option which gives the emulator the rights to communicate to the outside world? Thank you for your time ;-) great work so far :-*
Author
Owner

@budtmo commented on GitHub (Jul 5, 2019):

It should be fixed on the 1.8-p4. Please feel free to reopen the issue.

<!-- gh-comment-id:508663570 --> @budtmo commented on GitHub (Jul 5, 2019): It should be fixed on the [1.8-p4](https://github.com/budtmo/docker-android/releases/tag/1.8-p4). Please feel free to reopen the issue.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/docker-android#61
No description provided.