Home > Mobile >  docker container didn't send any data
docker container didn't send any data

Time:05-20

running docker build -t <IMAGE_NAME> . then running docker run -p 8080:8080 <IMAGE_NAME> logs to console that it works but 127.0.0.1:8080 does not display the client

https://user-images.githubusercontent.com/72412733/169354228-2ab6bc5b-4cdd-4026-afe4-5c41f8c50717.png

https://user-images.githubusercontent.com/72412733/169354294-f0140f59-dbe7-4327-bceb-afcf75681f9a.png

Dockerfile:

FROM rust:1.60.0-slim-buster

WORKDIR /app

COPY . .

RUN rustup target add wasm32-unknown-unknown
RUN cargo install --locked --version 0.15.0 trunk
RUN trunk build --release

EXPOSE 8080

CMD ["trunk", "serve", "--release"]

Cargo.toml

[package]
name = "yew-whos-that-pokemon-client"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
getrandom = { version = "0.2.4", features = ["js"] }
rand = "0.8.5"
reqwest = "0.11.10"
serde_json = "1.0.81"
wasm-bindgen-futures = "0.4.30"
web-sys = "0.3.57"
yew = "0.19.3"

this works perfectly fine locally and i tried with multiple browsers

reference to source code if needed to solve this issue: https://github.com/apinanyogaratnam/yew-whos-that-pokemon-client

any help will be appreciated, thanks

CodePudding user response:

server listening at http://127.0.0.1:8080 means that the server will only accept connections from 127.0.0.1, i.e. localhost.

In a container, localhost is the container itself, so your program won't accept connections from outside the container.

To get it to do that, you should have your program bind to 0.0.0.0 which will cause it to accept connections from anywhere.

I'm not a Rust expert, but it seems there's an --address option on trunk serve you can use to tell it what address to bind to. I haven't been able to find an example. Only these release notes where they say they've changed the default bind address from 0.0.0.0 to 127.0.0.1 for security reasons and introduced the --address option in case you need to set another address.

Update: I tried downloading your project and if I change the CMD statement in the Dockerfile to

CMD ["trunk", "serve", "--release", "--address", "0.0.0.0"]

it works.

  • Related