运行Java相当于“docker exec -ti {容器} curl”

我有一个docker容器configuration为运行Nginx和redirectstream量。 我正在docker容器外运行验收testing,并需要我的URL请求被redirect。

目前从命令行运行“docker exec -ti {container} curl”会返回我想要的响应,但是我的Unirest HTTP客户端并不是通过容器发送请求(因为我没有告诉它,不确定如何/如果我可以)。

我认为我的解决scheme是在我的testing中编程创build“docker exec curl”请求来实现这个结果,但似乎无法find如何。 如果有人有一个想法如何实现这一点,将不胜感激。

您需要为此使用dynamic端口映射

 $ ID=$(docker run -P -d nginx) $ PORT=$(docker port $ID | grep "80/tcp" | cut -d":" -f2) $ curl http://localhost:${PORT}/ <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>