我的ASP.Net Core应用程序能够使用Docker连接到postGres数据库,并且Docker compose成功(请参阅下面的Docker-Compose up输出)。但是,我无法从PC分别使用URL SELECT * FROM
(SELECT
times_show_up,
COUNT(user_id) AS num_users,
group_name1,
group_name2
FROM
(
SELECT
user_id,
COUNT(*) AS times_show_up,
group_name1,
group_name2
FROM
table1
INNER JOIN
(SELECT DISTINCT user_id, group_name2 FROM table2) t2
USING(user_id)
GROUP BY user_id, group_name1, group_name2
) t1
GROUP BY times_show_up, group_name1, group_name2) t9
UNION ALL
(SELECT
0 AS times_show_up,
SUM(CASE WHEN t1.user_id IS NULL
THEN 1 ELSE 0 END) AS num_users,
'groupA' AS group_name1,
group_name2
FROM
table2
LEFT JOIN
(SELECT user_id FROM table1 WHERE group_name1 = 'groupA') t1
USING(user_id)
GROUP BY group_name2)
UNION ALL
(SELECT
0 AS times_show_up,
SUM(CASE WHEN t1.user_id IS NULL
THEN 1 ELSE 0 END) AS num_users,
'groupB' AS group_name1,
group_name2
FROM
table2
LEFT JOIN
(SELECT user_id FROM table1 WHERE group_name1 = 'groupB') t1
USING(user_id)
GROUP BY group_name2)
--- ORDER BY group_name1, group_name2, times_show_up
或http://IP_AddressOfRunningDockerContainer:443
浏览docker容器上的ASP.Net Core应用程序或adminer(Postgres客户端)。
我可能会缺少什么?
获取容器IP地址(及其输出)的命令:
http://IP_AddressOfRunningDockerContainer:8080
Docker-组合输出:
docker inspect -f "{{ .NetworkSettings.IPAddress }}" <containerId>
IP_AddressOfRunningDockerContainer
Docker-Compose.yml:
db_1 | 2019-08-21 01:52:03.905 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2019-08-21 01:52:03.905 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2019-08-21 01:52:03.925 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2019-08-21 01:52:03.964 UTC [22] LOG: database system was shut down at 2019-08-21 01:30:03 UTC
db_1 | 2019-08-21 01:52:03.999 UTC [1] LOG: database system is ready to accept connections
adminer_1 | PHP 7.3.7 Development Server started at Wed Aug 21 01:22:13 2019
adminer_1 | Listening on http://[::]:8080
adminer_1 | Document root is /var/www/html
adminer_1 | Press Ctrl-C to quit.
adminer_1 | PHP 7.3.7 Development Server started at Wed Aug 21 01:23:47 2019
adminer_1 | Listening on http://[::]:8080
adminer_1 | Document root is /var/www/html
adminer_1 | Press Ctrl-C to quit.
adminer_1 | PHP 7.3.7 Development Server started at Wed Aug 21 01:27:23 2019
adminer_1 | Listening on http://[::]:8080
adminer_1 | Document root is /var/www/html
adminer_1 | Press Ctrl-C to quit.
adminer_1 | PHP 7.3.7 Development Server started at Wed Aug 21 01:52:03 2019
scrubber_1 | Hosting environment: Development
scrubber_1 | Content root path: /app
scrubber_1 | Now listening on: https://[::]:443
scrubber_1 | Now listening on: http://[::]:80
scrubber_1 | Application started. Press Ctrl+C to shut down.
应用dockerFile.yml:
version: '3.4'
docker
networks:
frontend:
backend:
services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: <SomeStrongPassword>
POSTGRES_DB: scrubber
POSTGRES_USER: ajitgoel
networks:
backend:
adminer:
image: adminer
restart: always
ports:
- 8080:8080
networks:
backend:
scrubber:
image: ${DOCKER_REGISTRY-}scrubber
environment:
- ASPNETCORE_ENVIRONMENT=PRODUCTION
build:
context: .
dockerfile: Dockerfile
networks:
frontend:
backend:
depends_on:
- db
答案 0 :(得分:2)
您不能使用其IP从主机访问容器。您需要映射主机上的公开端口。就像您已经为D3DX12.h
做过的一样。
您的adminer
服务应该已经在以下位置可用:adminer
要使其他容器可用,您需要将服务声明更改为此:
http://localhost:8080
然后通过 scrubber:
image: ${DOCKER_REGISTRY-}scrubber
environment:
- ASPNETCORE_ENVIRONMENT=PRODUCTION
build:
context: .
dockerfile: Dockerfile
networks:
frontend:
backend:
depends_on:
- db
ports:
- 8888:80
- 8443:443
或http://localhost:8888
访问该应用程序。
如果主机上的端口80和443空闲,则可以分别用80和443替换8888和8443。