coc28
coc28

Reputation: 13

How to link selenium server via docker compose

How to link selenium server via docker compose to another container? My docker-compose.yml is:

 version: '2'
    services:
        selenium:
            image: selenium/standalone-chrome
            ports:
                - "4444:4444"
        lamp:
            build: ./lamp
            ports:
                - "3306:3306"
                - "80:80"
            volumes:
                - /projects:/var/www/projects
            links:
                - selenium

then

sudo docker exec -it composelamp_lamp_1 /bin/bash
root@68a87ec3325f:/# curl http://127.0.0.1:4444/wd/hub
curl: (7) Failed to connect to 127.0.0.1 port 4444: Connection refused

What am I doing wrong?

Upvotes: 1

Views: 1880

Answers (2)

dnephin
dnephin

Reputation: 28060

127.0.0.1 is wrong. They are different containers, so the host is not localhost.

Try: http://selenium:4444/wd/hub

The service name is added as a hostname alias for the container

Upvotes: 4

RichArt
RichArt

Reputation: 1672

I cannot comment, so I write an answer:

Can you check if the port 4444 is already used by another application? Or may be just publish another port. Try for example something like:

ports:
    - "19900:4444"

and then try to connect to http://127.0.0.1:19900/wd/hub

I hope it helps.

edit : it can also be, that your application is not running on your localhost (127.0.0.1). In that case you should figure out on what IP address it's running.

Upvotes: 0

Related Questions