开发者

Problem to scrap a web service in a container from another container with selenium with different ip

开发者 https://www.devze.com 2022-12-07 20:50 出处:网络
I have two containers running to run prestashop and another for mysql, I raise them using docker-compose, and I access with localhost:8081 from the browser without problems. Then I need another contai

I have two containers running to run prestashop and another for mysql, I raise them using docker-compose, and I access with localhost:8081 from the browser without problems. Then I need another container with selenium to access the prestashop page, the problem is that I need this container to have a different ip than the host (in my case 172.18.0.1). I am trying with this image: joyzoursky/python-chromedriver:3.9-selenium , I raise it with the following command:

docker run -it -w /usr/workspace --name selenium-1 --network=prestashop_default --link=ps-web -v $(pwd):/usr/workspace joyzoursky/python-chromedriver:3. 9-selenium bash

, where I connect it to the network that is already created from prestashop ( having ip 172.18.0.4), and I make a link to the prestashop container as well. The problem is that I can not access the prestashop page from the selenium container, I have tried with wget with the ip, the container name, localhost and nothing, I get this error: Connecting to 172.18.0.3:8081.... failed: Connection refused. When pinging 172.18.0.3 I get a response without problems. Changing --network= by host I can access to the page, but when I do this is through the ip of localhost(172.18.0.1).

When I inspect the created network which is prestashop_default I obtain the following result:

"Containers": {
            "5e925fa80c8a4bc8d7043052029435cd0df0184d8684b609a9ed0537320fe563": {
                "Name": "ps-mysql",
                "EndpointID": "1dccfc440969a274ea27d96b197c1f4673ecc20ee9ae8bf4ffb2448df73fe6e6",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            },
            "d86c2e4906f0d281ea8549fea780c5cacb8358271da8f804191129fcd8f3db4d": {
                "Name": "selenium-1",
                "EndpointID": "5b220ec8e06828e7312c07e9086261143143344dc06ee8724e32764627992610",
                "MacAddress": "02:42:ac:12:00:04",
                "IPv4Address": "172.18.0.4/16",
                "IPv6Address": ""
            },
            "eff4a94b148500a4979e752d8c903c222b06bc5ac1cc0ed2ef519f533dcf7ced": {
                "Name": "ps-web",
                "EndpointID": "4f5300acddc57de8b09d86441743b2开发者_C百科e6fa6f4fb5fdb74a57cfc0d4b52e0c227f",
                "MacAddress": "02:42:ac:12:00:03",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            }

Inside the selenium container I ping:

root@d86c2e4906f0:/usr/workspace# ping 172.18.0.3
PING 172.18.0.3 (172.18.0.3) 56(84) bytes of data.
64 bytes from 172.18.0.3: icmp_seq=1 ttl=64 time=0.218 ms
64 bytes from 172.18.0.3: icmp_seq=2 ttl=64 time=0.247 ms
> ^C
172.18.0.3 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 19ms
rtt min/avg/max/mdev = 0.218/0.232/0.247/0.021 ms

Where, as can be seen, everything is normal. When I use wget with the localhost, with the ip, or with the container combre I get the following:

root@d86c2e4906f0:/usr/workspace# wget localhost:8081
--2022-12-07 03:51:19--  http://localhost:8081/
Resolving localhost (localhost)... 127.0.0.1, ::1
Connecting to localhost (localhost)|127.0.0.1|:8081... failed: Connection refused.
Connecting to localhost (localhost)|::1|:8081... failed: Cannot assign requested address.
Retrying.
root@d86c2e4906f0:/usr/workspace# wget http://172.18.0.3:8081
--2022-12-07 03:51:35--  http://172.18.0.3:8081/
Connecting to 172.18.0.3:8081... failed: Connection refused.
root@d86c2e4906f0:/usr/workspace# wget http://ps-web:8081
--2022-12-07 03:51:57--  http://ps-web:8081/
Resolving ps-web (ps-web)... 172.18.0.3
Connecting to ps-web (ps-web)|172.18.0.3|:8081... failed: Connection refused.

As I explained at the beginning if I use the host network for the selenium container when I access the prestashop web service it is done from the ip 172.18.0.1 which is localhost and I don't need that, I need it to be from a different ip. How can I connect from the selenium container to the prestashop container using a different ip as I am trying to do?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号