How to change port of selenium/hub docker container? - selenium

I am executing automation tests using Docker containers. I have to run test suites for multiple applications on the same server. But if I have same port for each selenium hub docker container then I cannot run all these suites at the same time. Thus I want to assign different ports to each selenium/hub docker container. Is there any way I can change hub container's port? Or do I need to write my own dockerfile and not use selenium/hub docker images?
My docker-compose file looks like this
version: "3"
services:
selenium-hub:
restart: always
image: selenium/hub:latest
ports:
- "4444:4444"
environment:
- GRID_BROWSER_TIMEOUT=300
- GRID_TIMEOUT=300
selenium-chrome:
restart: always
image: selenium/node-chrome:latest
depends_on:
- selenium-hub
volumes:
- /dev/shm:/dev/shm
links:
- selenium-hub:hub
environment:
- HUB_PORT_4444_TCP_ADDR=selenium-hub
- HUB_PORT_4444_TCP_PORT=4444
- JAVA_OPT=-Xmx512m
- DBUS_SESSION_BUS_ADDRESS=/dev/null
- no_proxy=localhost
- HUB_ENV_no_proxy=localhost
- GRID_BROWSER_TIMEOUT=300
- GRID_TIMEOUT=300
selenium-firefox:
restart: always
image: selenium/node-firefox:latest
depends_on:
- selenium-hub
volumes:
- /dev/shm:/dev/shm
links:
- selenium-hub:hub
environment:
- HUB_PORT_4444_TCP_ADDR=selenium-hub
- HUB_PORT_4444_TCP_PORT=4444
- JAVA_OPT=-Xmx512m
- DBUS_SESSION_BUS_ADDRESS=/dev/null
- no_proxy=localhost
- HUB_ENV_no_proxy=localhost
- GRID_BROWSER_TIMEOUT=300
- GRID_TIMEOUT=300

You can change the ports using the SE_OPTS environment variable: just add
environment:
SE_OPTS: "-port <YOUR_PREFERED_PORT>"
to your docker-compose.yml and Selenium will start at <YOUR_PREFERED_PORT>.
See https://github.com/SeleniumHQ/docker-selenium#se_opts-selenium-configuration-options

According to the Dockerfile https://github.com/SeleniumHQ/docker-selenium/blob/master/Hub/Dockerfile you can set GRID_HUB_PORT
environment:
GRID_HUB_PORT: "4545"

Just do a find and replace of 4444 with whatever port you want to use. For example, use 4440 instead of 4444.
version: "3"
services:
selenium-hub:
restart: always
image: selenium/hub:latest
ports:
- "4440:4440"
environment:
- GRID_BROWSER_TIMEOUT=300
- GRID_TIMEOUT=300
selenium-chrome:
restart: always
image: selenium/node-chrome:latest
depends_on:
- selenium-hub
volumes:
- /dev/shm:/dev/shm
links:
- selenium-hub:hub
environment:
- HUB_PORT_4440_TCP_ADDR=selenium-hub
- HUB_PORT_4440_TCP_PORT=4440
- JAVA_OPT=-Xmx512m
- DBUS_SESSION_BUS_ADDRESS=/dev/null
- no_proxy=localhost
- HUB_ENV_no_proxy=localhost
- GRID_BROWSER_TIMEOUT=300
- GRID_TIMEOUT=300
selenium-firefox:
restart: always
image: selenium/node-firefox:latest
depends_on:
- selenium-hub
volumes:
- /dev/shm:/dev/shm
links:
- selenium-hub:hub
environment:
- HUB_PORT_4440_TCP_ADDR=selenium-hub
- HUB_PORT_4440_TCP_PORT=4440
- JAVA_OPT=-Xmx512m
- DBUS_SESSION_BUS_ADDRESS=/dev/null
- no_proxy=localhost
- HUB_ENV_no_proxy=localhost
- GRID_BROWSER_TIMEOUT=300
- GRID_TIMEOUT=300

I had a situation where I was conducting automated selenium tests for two different web applications on the same Jenkins machine. I needed 2 selenium grids to be set up and running on the same machine each employing unique and distinct ports. Instead of creating docker images of my own for the hubs and nodes I changed the docker compose file for the second selenium grid to the following:
version: "3.5"
services:
hub:
image: selenium/hub
container_name: selenium_hub_nia
ports:
- "3333:4444"
networks:
- nia_bridge
environment:
GRID_MAX_SESSION: 16
GRID_BROWSER_TIMEOUT: 10000
GRID_TIMEOUT: 10000
GRID_HUB_PORT: 3333
expose:
- "3333"
chrome:
image: selenium/node-chrome
container_name: selenium_node_nia_chrome
depends_on:
- hub
environment:
- HUB_PORT_4444_TCP_ADDR=hub
- HUB_PORT_4444_TCP_PORT=3333
- NODE_MAX_SESSION=4
- NODE_MAX_INSTANCES=4
volumes:
- /dev/shm:/dev/shm
ports:
- "9003:5900"
links:
- hub
networks:
- nia_bridge
firefox:
image: selenium/node-firefox-debug
container_name: selenium_node_nia_firefox
depends_on:
- hub
environment:
- HUB_PORT_4444_TCP_ADDR=hub
- HUB_PORT_4444_TCP_PORT=3333
- NODE_MAX_SESSION=4
- NODE_MAX_INSTANCES=4
volumes:
- /dev/shm:/dev/shm
ports:
- "9004:5900"
links:
- hub
networks:
- nia_bridge
networks:
nia_bridge: {}
Three major changes in the above file:
In the hub definition :
I first mapped the port 4444 of the second selenium hub container to the host (Jenkins server) port 3333 (the first hub continues to run on 4444). This solves the error of 4444 being bound already when the first selenium hub container is running.
I also defined its GRID_HUB_PORT as 3333 and exposed that port to the containers on the network bridge named nia-bridge.
In the two services for my 2 nodes (chrome and firefox), I specified the HUB_PORT_4444_TCP_PORT as 3333 so they use the correct url to register to the hub.
This docker compose file spins up 3 containers. I made the container names unique i.e. different from the pre-existing selenium grid network that you may already have for your other web application. This is required because docker container names must be unique.
The above helped me spin up a completely distinct selenium grid with the hub and 2 nodes running on ports 3333,9003,9004 respectively of the host Jenkins server.

Related

Openldap setup with server and UI fails

I'm trying to setup open ldap in linux VM and I am using openldap server from bitnami and
also the UI container. My docker-compose file is as follows:
version: '3'
networks:
openldap:
name: openldap
services:
openldap:
image: bitnami/openldap:latest
restart: unless-stopped
ports:
- '1389:1389'
- '1636:1636'
environment:
- LDAP_ORGANISATION=company
- LDAP_DOMAIN=company.network
- LDAP_ROOT=dc=company,dc=network
- LDAP_ADMIN_USERNAME=admin
- LDAP_ADMIN_PASSWORD=password
networks:
- openldap
volumes:
- 'openldap_data:/bitnami/openldap'
openldap-ui:
image: wheelybird/ldap-user-manager:latest
restart: unless-stopped
ports:
- 8082:80
environment:
- SERVER_HOSTNAME=localhost:8082
- LDAP_URI=ldap://openldap
- LDAP_BASE_DN=dc=company,dc=network
- LDAP_ADMINS_GROUP=admins
- LDAP_ADMIN_BIND_DN=cn=admin,dc=company,dc=network
- LDAP_ADMIN_BIND_PWD=password
- LDAP_IGNORE_CERT_ERRORS=true
- NO_HTTPS=true
networks:
- openldap
depends_on:
- openldap
volumes:
openldap_data:
driver: local
As per this documentation, when i try to do the initial setup via UI (http://ip-address:8082/setup), using the password 'password', I always get the following error.
Problem: Failed to bind as cn=admin,dc=company,dc=network
Wondering if anyone help identify what'm missing here?

Java Application on Docker (MySQL + Rabbit)

I am making an REST API which has a POST method which accepts a String as JSON and then sends it over RabbitMQ Topic and then a consumer is converting into entity and saving into a MySQL db.
Everything is running fine locally, but my task is to upload it on Docker and to be run online.
When I try to change "localhost" in properties with container names my Maven build fails....
How can i fix that?
I am putting my .properties:
spring.main.allow-bean-definition-overriding=true
spring.datasource.url=jdbc:mysql://localhost:3306/rabbit_messages?createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=1234
spring.rabbitmq.host = 127.0.0.1
spring.rabbitmq.port = 5672
spring.rabbitmq.username = guest
spring.rabbitmq.password = guest
and my docker-compose:
version: '3'
services:
my-app:
container_name: myapp
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
links:
- rabbitmq
- mysql
environment:
- SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3307/rabbit_messages?createDatabaseIfNotExist=true
- SPRING_DATASOURCE_USERNAME=root
- SPRING_DATASOURCE_PASSWORD=1234
- SPRING_RABBITMQ_HOST=rabbitmq
depends_on:
- rabbitmq
- mysql
java:
image: openjdk:latest
container_name: openjdk
rabbitmq:
image: rabbitmq:3-management
container_name: rabbitmq
ports:
- "5672:5672"
- "15672:15672"
erlang:
image: erlang:latest
container_name: erlang
mysql:
image: mysql:latest
container_name: mysql
ports:
- "3307:3307"
environment:
- MYSQL_DATABASE=rabbit_messages
- MYSQL_ROOT_PASSWORD=1234
- MYSQL_PASSWORD=1234
restart: on-failure

How can i use traefik2.0 in docker swarm, i don't know which labels ishould use

I want use traefik2.0 publish port 80 and 7000, the port 7000 is for frp(TCP). Now i am testing locally with 2.0 doc, i am using example on quick start but not running.
This is my docker compose file.
version: '3'
services:
reverse-proxy:
image: traefik:v2.0 # The official v2.0 Traefik docker image
command:
- "--api"
- "--entrypoints='Name:http Address::80'"
- "--providers.docker" # Enables the web UI and tells Traefik to listen to docker
- "--providers.docker.swarmmode=true"
- "--providers.docker.watch=true"
ports:
- "80:80" # The HTTP port
- "8080:8080" # The Web UI (enabled by --api)
networks:
- traefik-net
deploy:
replicas: 1
placement:
constraints:
- node.role == manager
labels:
- traefik.enable=false
volumes:
- /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
whoami:
image: containous/whoami # A container that exposes an API to show its IP address
networks:
- traefik-net
deploy:
labels:
- "traefik.http.routers.whoami.tls=true"
- "traefik.http.routers.whoami.entrypoints=https"
- "traefik.http.routers.whoami.rule=Host(`whoami.domain.com`)"
- "traefik.http.middlewares.whoami.redirectscheme.scheme=https"
networks:
traefik-net:
external: true
i expect which labels used on traefik2.0 can work
You're almost there!
Replace
- "--entrypoints='Name:http Address::80'"
with
- "--entryPoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
Enable the dashboard in a non-production environment. You'll also need to replace
- "--api" with
- "--api.insecure=true"
One of the labels of whoami has a mistake. There is no https entrypoint, it's now called websecure. So change
- "traefik.http.routers.whoami.entrypoints=https"
with
- "traefik.http.routers.whoami.entrypoints=websecure"
And finally expose the internal port that the whoami app is running on.
By adding this to the label of whoami
- traefik.http.services.whoami-service.loadbalancer.server.port=80
You should be able to verify it using the traefik dashboard on localhost:8080

Builds stuck in pending state drone

I'm using drone:0.8 with the following configuration but the only two first jobs are succeeded in building. The rest of jobs are stuck in the pending state.
I'm deploying drone using Docker Swarm stack deploy. Here is my configuration file:
version: '3'
services:
server:
image: drone/drone:0.8
ports:
- 8000
- 9000
volumes:
- /data/local/drone:/var/lib/drone/
environment:
- DRONE_OPEN=true
- DRONE_HOST=http://example.com
- DRONE_GITHUB=true
- DRONE_ORGS=my_fake_company
- DRONE_ADMIN=my_github
- DRONE_GITHUB_CLIENT=my_secret
- DRONE_GITHUB_SECRET=my_client
- DRONE_SECRET=my_drone_secret
- VIRTUAL_HOST=virtual_host.nginx.com
- VIRTUAL_PORT=8000
networks:
- edge
agent:
image: drone/agent:0.8
command: agent
depends_on:
- drone-server
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- DRONE_SERVER=drone_server:9000
- DRONE_SECRET=my_secret
networks:
- edge
networks:
- edge
external: true
It's running behind nginx-proxy by jwlinder.

Unsupported config option for services service: 'httpd'

I am getting this on Ubuntu with a fresh install of Docker 1.12.0
It works on all other colleagues installations with the same version of Docker.
This is the docker-compose.yml
version: '2'
networks:
backend:
services:
httpd:
image: httpd:2.4
depends_on:
- tomcat
networks:
- backend
ports:
- "80:80"
volumes:
- ./httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf
tomcat:
image: tomcat:8.0-jre8-alpine
depends_on:
- mongodb
networks:
- backend
ports:
- "8080:8080"
volumes:
- ./tomcat/webapps:/usr/local/tomcat/webapps/
environment:
- ITONICS_CONFIG=docker
- CATALINA_OPTS=-Xms512M -Xmx2048M
mongodb:
image: mongo:3.2
volumes:
- ./mongo/db:/data/db
networks:
- backend
ports:
- "27017:27017"