I have a very simple frontend and a very simple express.js server that runs inside docker. I’d like to run them in CI/CD for browser testing like Selenium. But no matter what I tried I can’t connect to the server inside the ci/cd job.
I tried running the docker
Hi @ettinger.boris
You need to use curl http://docker:5000 to reach your container running in DinD. Because you are connecting to ‘host’ where DinD is running and you have exposed a port.
Like this
stages:
- test
job:
stage: test
services:
- docker:dind
image: docker
script:
# start container in DinD
- docker run -d --name nginx -p 8000:80 nginx:latest
# use sleep in case your app takes some time to start
- sleep 10
# try to execute something inside, just for debug
- docker exec nginx curl http://localhost
# curl nginx container
- curl "http://docker:8000"
@balonik
Thanks for the reply.
I understand the part about service aliases.
What I don’t understand is how can the service reach the host or another service. E.g. if I have my server running and a service needs to reach it - doesn’t look like it’s working.
The services are reachable by the job image. I don’t know if it works the other way around. If services doesn’t work, just start the selenium container in the DinD next to your App. It doesn’t make any difference really.
Hi @balonik Thank you for your help. I reread your first post and realized that I needed to go to http://docker instead of http://localhost when running d-in-d. I’ll mark your answer as a solution.
I’m still unable to run selenium properly so I switched so cypress.io who are committed to CI/CD including maintaining working docker images.