I have 2 services, I will briefly describe the important settings:
server_android:
network_mode: "host"
depends_on:
- android
ports:
- "127.0.0.1:8001:80"
command: >
sh -c "
adb wait-for-device && adb root && adb remount && \
adb push ./rest-api /data/data && adb shell chmod 755 /data/data/rest-api && \
adb shell /data/data/rest-api
"
android:
network_mode: "host"
command: >
sh -c "adb start-server && \
emulator -avd test -no-audio -no-window -no-snapshot-load -no-boot-anim -writable-system -read-only"
From the command descriptions, we can see that the server_android
service starts the rest-api
server on android, which runs on the android
service.
Server output:
2024-09-24T18:12:13.900118Z INFO Server running at http://127.0.0.1:80
If you make a get request from inside the server_android
service to a running server, it will get it:
PS D:\VS Code Projects\rust\mertex\rust-scales-library> docker-compose exec server_android wget localhost:80
--2024-09-24 21:17:38-- http://localhost/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:80... failed: Connection refused.
Connecting to localhost (localhost)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2024-09-24 21:17:38 ERROR 404: Not Found.
– this connectivity is achieved through a shared network connection:
network_mode: "host"
My task is to make a similar request to the server from the local machine on which docker is running. I opened the port in the configuration as I thought was correct:
ports:
- "127.0.0.1:8001:80"
Then executed the query:
root@mywin:/mnt/d/VS Code Projects/rust/mertex/rust-scales-library# wget localhost:8001
--2024-09-24 21:21:24-- http://localhost:8001/
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:8001... failed: Connection refused.
which says that there is no connection to the server via the server_android
service.
I don’t know much about the docker network, so please help me to establish this connection.