Docker容器没有发送任何数据
运行docker build -t< image_name> 。
/I.sstatic.net/hfv2y.png“ rel =” nofollow noreferrer“>
“ img src =“ https://i.sstatic.net/gknuo.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"
这在本地效果很好,
如果需要,我尝试使用多个浏览器引用源代码来解决此问题: https://github.com/apinanyogaratnam/yew-whos-whos-that-pokemon-client
任何帮助都将不胜感激,谢谢
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
服务器在http://127.0.0.1:8080
在http://127.0.0.1:8080 表示服务器仅接受127.0.0.1.1(即Localhost)的连接。在容器中,Localhost是容器本身,因此您的程序将不接受容器外部的连接。
为了做到这一点,您应该让程序绑定到
0.0.0.0
,这将导致其接受从任何地方接受连接。我不是生锈的专家,但是似乎有一个
-
on trunk serve 您可以用来告诉它要绑定到什么地址。我找不到一个例子。仅这些发行笔记地址从0.0.0.0
到127.0.0.1
出于安全原因,并引入了- 地址> - 地址
选项,以防您需要设置另一个地址。更新:我尝试下载您的项目,如果将Dockerfile中的CMD语句更改为
有效。
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 ontrunk 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 from0.0.0.0
to127.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
it works.