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
For the company I work at, I setup a docker environment using docker-composer and multiple containers so we can all benefit from having the same environment. I created a subdomain DNS record (dev.company.com) pointing to 127.0.0.1. This works fine for reaching projects from within the browser to the appropriate Apache vhosts. The problem however is that we cannot resolve this domain within the PHP container because the DNS points towards 127.0.0.1 how can I add a custom entry to the docker php container to resolve *.dev.company.com to the Apache container?
Also adding this to /etc/hosts is not really an option because we run like 50+ projects.
I found some solutions online which just said to add php to the same container, but this kinda defeats the purpose of having separate containers per service. Added docker-composer file as reference.
Note: I'm the only one using Linux in the office other colleagues are using Docker on Windows or Mac, so a Linux only solution won't cut it :)
version: "3.7"
services:
php:
build: php
env_file:
- ./conf/php.config.env
volumes:
- ./htdocs:/htdocs
expose:
- "9000"
links:
- mysql
- mssql
- mail
restart: always
init: true
apache:
build: apache
volumes:
- ./htdocs:/htdocs:ro
ports:
- "80:80"
- "443:443"
links:
- php
restart: always
init: true
mysql:
build: mysql
env_file:
- ./conf/mysql.config.env
volumes:
- ./mysql/data:/var/lib/mysql
ports:
- "3306:3306"
restart: always
mssql:
image: microsoft/mssql-server-linux
env_file:
- ./conf/mssql.config.env
volumes:
- ./mssql/data:/var/opt/mssql/data
ports:
- "1433:1433"
restart: always
mail:
image: schickling/mailcatcher
ports:
- "1080:1080"
restart: always
init: true
redis:
image: redis
expose:
- "6379"
links:
- php
restart: always
init: true
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.
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.
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"