Java Application on Docker (MySQL + Rabbit) - rabbitmq

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

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?

Running multiple docker-compose files with nginx reverse proxy

I asked a question here and got part of my problem solved, but I was advised to create another question because it started to get a bit lengthy in the comments.
I'm trying to use docker to run multiple PHP,MySQL & Apache based apps on my Mac, all of which would use different docker-compose.yml files (more details in the post I linked). I have quite a few repositories, some of which communicate with one another, and not all of them are the same PHP version. Because of this, I don't think it's wise for me to cram 20+ separate repositories into one single docker-compose.yml file. I'd like to have separate docker-compose.yml files for each repository and I want to be able to use an /etc/hosts entry for each app so that I don't have to specify the port. Ex: I would access 2 different repositories such as http://dockertest.com and http://dockertest2.com (using /etc/hosts entries), rather than having to specify the port like http://dockertest.com:8080 and http://dockertest.com:8081.
Using the accepted answer from my other post I was able to get one app running at a time (one docker-compose.yml file), but if I try to launch another with docker-compose up -d it results in an error because port 80 is already taken. How can I runn multiple docker apps at the same time, each with their own docker-compose.yml files and without having to specify the port in the url?
Here's a docker-compose.yml file for the app I made. In my /etc/hosts I have 127.0.0.1 dockertest.com
version: "3.3"
services:
php:
build: './php/'
networks:
- backend
volumes:
- ./public_html/:/var/www/html/
apache:
build: './apache/'
depends_on:
- php
- mysql
networks:
- frontend
- backend
volumes:
- ./public_html/:/var/www/html/
environment:
- VIRTUAL_HOST=dockertest.com
mysql:
image: mysql:5.6.40
networks:
- backend
environment:
- MYSQL_ROOT_PASSWORD=rootpassword
nginx-proxy:
image: jwilder/nginx-proxy
networks:
- backend
ports:
- 80:80
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
networks:
frontend:
backend:
I would suggest to extract the nginx-proxy to a separate docker-compose.yml and create a repository for the "reverse proxy" configuration with the following:
A file with extra contents to add to /etc/hosts
127.0.0.1 dockertest.com
127.0.0.1 anothertest.com
127.0.0.1 third-domain.net
And a docker-compose.yml which will have only the reverse proxy
version: "3.3"
services:
nginx-proxy:
image: jwilder/nginx-proxy
ports:
- 80:80
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
Next, as you already mentioned, create a docker-compose.yml for each of your repositories that act as web endpoints. You will need to add VIRTUAL_HOST env var to the services that serve your applications (eg. Apache).
The nginx-proxy container can run in "permanent mode", as it has a small footprint. This way whenever you start a new container with VIRTUAL_HOST env var, the configuration of nginx-proxy will be automatically updated to include the new local domain. (You will still have to update /etc/hosts with the new entry).
If you decide to use networks, your web endpoint containers will have to be in the same network as nginx-proxy, so your docker-compose files will have to be modified similar to this:
# nginx-proxy/docker-compose.yml
version: "3.3"
services:
nginx-proxy:
image: jwilder/nginx-proxy
ports:
- 80:80
networks:
- reverse-proxy
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
networks:
reverse-proxy:
# service1/docker-compose.yml
version: "3.3"
services:
php1:
...
networks:
- backend1
apache1:
...
networks:
- nginx-proxy_reverse-proxy
- backend1
environment:
- VIRTUAL_HOST=dockertest.com
mysql1:
...
networks:
- backend1
networks:
backend1:
nginx-proxy_reverse-proxy:
external: true
# service2/docker-compose.yml
version: "3.3"
services:
php2:
...
networks:
- backend2
apache2:
...
networks:
- nginx-proxy_reverse-proxy
- backend2
environment:
- VIRTUAL_HOST=anothertest.com
mysql2:
...
networks:
- backend2
networks:
backend2:
nginx-proxy_reverse-proxy:
external: true
The reverse-proxy network that is created in nginx-proxy/docker-compose.yml is referred as nginx-proxy_reverse-proxy in the other docker-compose files because whenever you define a network - its final name will be {{folder name}}_{{network name}}
If you want to have a look at a solution that relies on browser proxy extension instead of /etc/hosts, check out mitm-proxy-nginx-companion

How to change port of selenium/hub docker container?

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.

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"