我一直试图看到我的网页应用程序从我的docker-compose文件启动,但什么也没有出现。它的工作时,我的应用程序在本地服务,但不通过docker。我正在使用rust和actix-web为我的后端设置在端口8080上的localhost,我正在暴露端口的docker-compose,但它仍然不工作。
我的Dock合成文件:
services:
database:
image: postgres
restart: always
expose:
- 5432
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: zion
PGDATA: /var/lib/postgresql/data/
healthcheck:
test: ["CMD", "pg_isready", "-d", "zion", "-U", "postgres"]
timeout: 25s
interval: 10s
retries: 5
networks:
- postgres-compose-network
test:
build:
context: .
dockerfile: Dockerfile
entrypoint: ./test-entrypoint.sh
depends_on:
database:
condition: service_healthy
networks:
- postgres-compose-network
server:
build:
context: .
dockerfile: Dockerfile
entrypoint: ./run-entrypoint.sh
restart: always
expose:
- 8080
ports:
- 8080:8080
depends_on:
database:
condition: service_healthy
networks:
- postgres-compose-network
networks:
postgres-compose-network:
driver: bridge
后端main.rs
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
log::info!("starting HTTP server at http://localhost:8080");
let secret_key = Key::generate();
let pool = establish_connection();
log::info!("database connection established");
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(pool.clone()))
.wrap(middleware::Logger::default())
.wrap(IdentityMiddleware::default())
.configure(database::routes::user::configure)
.service(
Files::new("/", "../frontend/dist")
.prefer_utf8(true)
.index_file("index.html"),
)
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}
1条答案
按热度按时间sq1bmfud1#
根据@David-Maze提供的答案,我将应用程序地址绑定到0.0.0.0,而不是127.0.0.1