Docker容器没有发送任何数据

发布于 2025-01-30 14:47:26 字数 1320 浏览 6 评论 0原文

运行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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入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.0127.0.0.1出于安全原因,并引入了- 地址> - 地址选项,以防您需要设置另一个地址。

更新:我尝试下载您的项目,如果将Dockerfile中的CMD语句更改为

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

有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文