I developed a website using Docker for its backend side. There are some components such as Selenium, Chrome Driver and MySQL which are integrated in docker-compose file. The problem is that when I move my project to VPS server (CentOS), docker compose could not be created properly and returns the following error:
web_1 | crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
web_1 | Application startup exception
web_1 | OpenQA.Selenium.WebDriverException: An unknown exception was encountered sending an HTTP request to the remote WebDriver server for URL http://selenium-hub:4444/wd/hub/session. The exception message was: Connection refused (selenium-hub:4444)
web_1 | ---> System.Net.Http.HttpRequestException: Connection refused (selenium-hub:4444)
web_1 | ---> System.Net.Sockets.SocketException (111): Connection refused
web_1 | at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
web_1 | at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
web_1 | at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|283_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
The interesting point is that containers are created and run flawlessly in my local host, but when I run them on VPS Server I am faced with this error.
This is my docker-compose file:
version: "3"
volumes:
datafiles:
services:
database:
image: mysql:8.0.28
depends_on:
- selenium-hub
ports:
- "3307:3306"
volumes:
- datafiles:/var/lib/mysql
- "~/sql-scripts/setup.sql:/docker-entrypoint-initdb.d/1.sql"
restart: always
environment:
MYSQL_ROOT_PASSWORD: *****
MYSQL_USER: sa
MYSQL_PASSWORD: ******
MYSQL_DATABASE: Pan
chrome:
image: selenium/node-chrome:4.3.0-20220706
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
selenium-hub:
image: selenium/hub:4.3.0-20220706
container_name: selenium-hub
ports:
- "4442:4442"
- "4443:4443"
- "4444:4444"
web:
build: .
ports:
- "8080:80"
depends_on:
- database
- selenium-hub
- chrome
restart: always
And this is a piece of code I create my driver:
ChromeOptions options = new ChromeOptions();
options.AddArgument("no-sandbox");
options.AddArgument("headless");
driver = new RemoteWebDriver(new Uri("http://selenium-hub:4444/wd/hub"), options);
The way comes to my mind is that either I should modify my docker-compose file or give some permissions in VPS server to Docker.