docker / compose

Define and run multi-container applications with Docker
https://docs.docker.com/compose/
Apache License 2.0
34.23k stars 5.26k forks source link

[BUG] Ports that are established after running the container from within are not accessible #12135

Closed youssefehaab closed 2 months ago

youssefehaab commented 2 months ago

Description

I am trying to containerize E2E test automation, which automates a Flutter application on real Android devices. I managed to connect to the host's ADB daemon to establish the mobile device connection. While I was successful in connecting to the ADB, I was unsuccessful in connecting to UiAutomator2.

Here's how it works:

  1. ADB establishes a connection to the Android device.
  2. ADB installs the Appium Settings app.
  3. ADB installs the Flutter app.
  4. The UiAutomator2 driver starts the server on port 8201 on localhost and begins automating the app.

The issue is that, for example, before I run the container, I have a port in use (8081). When the container starts, I am able to curl on this port from the container's bash. However, I am not able to curl on port 8201, which was created by the UiAutomator2 driver from within the container.

Steps To Reproduce

Create docker image and include:

  1. Install the necessary tools to be able to automate flutter application using Appium
  2. Set Environment variables
  3. Copy source code on the container
  4. Run the tests

Compose Version

version: '3'
services:
  farm:
    image: {IMAGE_NAME}
    container_name: {CONTAINER_NAME}
    privileged: true
    network_mode: host
    hostname: localhost
    environment:
      - ANDROID_ADB_SERVER_ADDRESS=host.docker.internal
    volumes:
      - /Users/.m2:/home/myuser/.m2

Docker Environment

Client:
 Version:    24.0.6
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2-desktop.5
    Path:     /Users/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.23.0-desktop.1
    Path:     /Users/.docker/cli-plugins/docker-compose
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     /Users/.docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.20
    Path:     /Users/.docker/cli-plugins/docker-extension
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v0.1.0-beta.9
    Path:     /Users/.docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/.docker/cli-plugins/docker-sbom
  scan: Docker Scan (Docker Inc.)
    Version:  v0.26.0
    Path:     /Users/.docker/cli-plugins/docker-scan
  scout: Docker Scout (Docker Inc.)
    Version:  v1.0.9
    Path:     /Users/.docker/cli-plugins/docker-scout

Server:
 Containers: 7
  Running: 5
  Paused: 0
  Stopped: 2
 Images: 15
 Server Version: 24.0.6
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8165feabfdfe38c65b599c4993d227328c231fca
 runc version: v1.1.8-0-g82f18fe
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
  cgroupns
 Kernel Version: 6.4.16-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 10
 Total Memory: 7.661GiB
 Name: linuxkit-cadba7c39623
 ID: 
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: daemon is not using the default seccomp profile

Anything else?

[ADB] Running '/usr/lib/android-sdk/platform-tools/adb -P 5037 -s RR8W802EFNN install -r -g /home/myuser/app-debug.apk' [ADB] The installation of 'app-debug.apk' took 7979ms [ADB] Install command stdout: Performing Streamed Install [ADB] Success [AndroidUiautomator2Driver@9de5 (9d152cd0)] Performing shallow cleanup of automation leftovers [AndroidUiautomator2Driver@9de5 (9d152cd0)] No obsolete sessions have been detected (connect ECONNREFUSED 127.0.0.1:8200) [ADB] Running '/usr/lib/android-sdk/platform-tools/adb -P 5037 -s RR8W802EFNN shell am force-stop io.appium.uiautomator2.server.test' [AndroidUiautomator2Driver@9de5 (9d152cd0)] Starting UIAutomator2 server 5.12.16 [AndroidUiautomator2Driver@9de5 (9d152cd0)] Using UIAutomator2 server from '/home/myuser/.appium/node_modules/appium-flutter-driver/node_modules/appium-uiautomator2-driver/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v5.12.16.apk' and test from '/home/myuser/.appium/node_modules/appium-flutter-driver/node_modules/appium-uiautomator2-driver/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk' [AndroidUiautomator2Driver@9de5 (9d152cd0)] Waiting up to 30000ms for UiAutomator2 to be online... [ADB] Creating ADB subprocess with args: ["-P","5037","-s","RR8W802EFNN","shell","am","instrument","-w","-e","disableAnalytics","true","io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner"] [AndroidUiautomator2Driver@9de5 (9d152cd0)] Matched '/status' to command name 'getStatus' [AndroidUiautomator2Driver@9de5 (9d152cd0)] Proxying [GET /status] to [GET http://127.0.0.1:8200/status] with no body [AndroidUiautomator2Driver@9de5 (9d152cd0)] connect ECONNREFUSED 127.0.0.1:8200 [AndroidUiautomator2Driver@9de5 (9d152cd0)] Matched '/status' to command name 'getStatus' [AndroidUiautomator2Driver@9de5 (9d152cd0)] Proxying [GET /status] to [GET http://127.0.0.1:8200/status] with no body [AndroidUiautomator2Driver@9de5 (9d152cd0)] connect ECONNREFUSED 127.0.0.1:8200

ndeloof commented 2 months ago

Can you confirm this issue applies to Docker Compose and is not a more global Docker issue? Try running the same container with a plain docker run ... command to confirm you don't get the same issue

youssefehaab commented 2 months ago

@ndeloof It is indeed a global Docker issue. I have tried running

docker run \
 -v /Users/.m2:/home/myuser/.m2 \
 -e ANDROID_ADB_SERVER_ADDRESS=host.docker.internal \
--network host \
--privileged \
--hostname localhost \
{IMAGE_NAME}

and I still face the same issue. Should I move this issue to another repo?

ndeloof commented 2 months ago

please report to github.com/moby/moby or maybe https://github.com/docker/for-mac as this may be specific to Docker Desktop