[英]Docker compose can't access ports of other containers
I have 2 containers running with docker compose.我有 2 个使用 docker 组合运行的容器。 One of the containers is executing a shell script which should check if the other container has already started and is running on port 9990.
其中一个容器正在执行 shell 脚本,该脚本应检查另一个容器是否已经启动并在端口 9990 上运行。
Even though the container is starting, the shell script echos nothing.即使容器正在启动,shell 脚本也没有回应。
keycloak:
image: jboss/keycloak:latest
volumes:
- ./imports/cache_reload/disable-theme-cache.cli:/opt/jboss/startup-scripts/disable-theme-cache.cli
- ./imports/themes/custom/:/opt/jboss/keycloak/themes/custom-theme/
- ./imports/realm/realm-export.json:/opt/jboss/realms/custom-import.json
environment:
DB_VENDOR: MYSQL
DB_ADDR: mysql
DB_DATABASE: keycloak
DB_USER: keycloak
DB_PASSWORD: password
KEYCLOAK_USER: admin
KEYCLOAK_PASSWORD: Pa55w0rd
ports:
- 8080:8080
depends_on:
- mysql
keycloak_installer:
image: solr:6.6-alpine
volumes:
- ./imports/scripts/import-realm.sh:/docker-entrypoint-initdb.d/init.sh
depends_on:
- keycloak
The shell script is the following: shell 脚本如下:
echo "MOIN LEUDE TRYMACS HIER!"
while ! nc -z localhost 9990; do
sleep 1
echo "Waiting for keycloak server startup 9990..."
echo "$(nc -z localhost 9990)"
done
The first echo is printed, but then nothing else is printed.打印了第一个回声,但随后没有打印任何其他内容。
The container keycloak is running on Port 9990.容器 keycloak 在端口 9990 上运行。
Please help, thanks请帮忙,谢谢
You have to understand more detail about network in docker compose.您必须在 docker compose 中了解有关网络的更多详细信息。
To solve your issue, you need:要解决您的问题,您需要:
ports:
- 8080:8080
networks:
- keycloak_network
On the second container (named keycloak_installer ) (you must expose the port that you want to request in the first container):在第二个容器(名为keycloak_installer )上(您必须在第一个容器中公开要请求的端口):
depends_on:
- keycloak
networks:
- keycloak_network
nc -z keycloak_installer 9990
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.