DropWizard app cannot be accessed from outside Docker - docker

I have a DropWizard application which I'm trying to run inside a Docker.
I'm using the following command.
docker run -v `pwd`:/app -t --expose 8080 -p 8080:8080 openjdk bash -c "cd app && java -jar build/libs/app.jar server infrastructure/config/config.yml"
but when I navigate to http://localhost:8080/swagger/ui I get a localhost refused to connect. error.
But if I used the following command to go inside the docker first and then run the dropwizard application from there and then wget from inside the application, I can see the application is really running. But i still can't access it from outside the Docker.
docker run -i -v `pwd`:/app -t --expose 8080 -p 8080:8080 openjdk bash
then
root#06a1c2648236:/# cd app && java -jar build/libs/app.jar server infrastructure/config/config.yml &
then
wget localhost:8080
This means the application is running in the container, but I can't access it outside from the container.

Related

Dockerized JMeter not sending requests to Dockerized Microservice

I have a small Spring Boot API running in docker. Shown below Is the command I used to up the container.
docker run -d --rm --name factorialorialContainer --memory=$2 --cpus=$3 -p 8080:8080 -e JAVA_OPTIONS="$(cat /Users/sulekahelmini/Documents/fyp/fyp_work/MLscripts/flags.txt)" suleka96/factorial:latest
Then I have a dockerized JMeter which I up using the below command
export volume_path=/Users/sulekahelmini/Documents/fyp/fyp_work/MLscripts/jmeter_resource && export jmeter_path=/jmeter && docker run --rm --name jmeterContainer --memory='512m' --cpus=2 -e JAVA_OPTS="-Xms512 -Xmx512" --volume ${volume_path}:${jmeter_path} egaillardon/jmeter --nongui -t factorial.jmx -l jmeter_results.jtl -q user.properties
but all the tests fail and requests are not getting sent to the API. This is how the CLI of JMeter looks
test config of request:
Protocol: htttp
Server: localhost
Port:8080
Method:GET
Path:/api/factorial
This is what the complete bash file looks like:
#!/bin/bash
cd /Users/sulekahelmini/Documents/fyp/fyp_work/demo/target && docker build . -t suleka96/factorial
docker run -d --rm --name factorialorialContainer --memory='512m' --cpus=2 -p 8080:8080 -e JAVA_OPTIONS="$(cat /Users/sulekahelmini/Documents/fyp/fyp_work/MLscripts/flags_base.txt)" suleka96/factorial:latest
sleep 15
#run test
export volume_path=/Users/sulekahelmini/Documents/fyp/fyp_work/MLscripts/jmeter_resource && export jmeter_path=/jmeter && docker run --rm --name jmeterContainer --memory='512m' --cpus=2 -e JAVA_OPTS="-Xms512 -Xmx512" --volume ${volume_path}:${jmeter_path} egaillardon/jmeter --nongui -t factorial.jmx -l jmeter_results.jtl -q user.properties
sleep 15
#jtl split
java -jar /Users/sulekahelmini/Documents/fyp/fyp_work/MLscripts/jtl-splitter-0.4.6-SNAPSHOT.jar -f /Users/sulekahelmini/Documents/fyp/fyp_work/MLscripts/jmeter_resource/jmeter_results.jtl -s -t 1;
docker stop factorialorialContainer
docker stop jmeterContainer
What am I doing wrong? How can I fix this?
You're doing wrong absolutely everything.
When it comes to Spring Boot even "small" API is not small at all, if you want something really small - consider i.e. Jersey
I fail to see why do you need containers at all, in your situation they don't add any value but only consume resources
You're running the application under test and the load generator at the same physical machine. Both can be very resource intensive when it comes to high load and you won't be able to tell for sure where is the bottleneck
If you still want to ignore previous 2 points and proceed: you're using localhost in JMeter container and there is nothing deployed on port 8080 in that container. You need to run the following command:
docker inspect factorialorialContainer
you will see a line which looks like:
"IPAddress": "xxx.xxx.xxx.xxx",
you will need to get this IP address from the docker inspect command output and replace the localhost with this IP address in the JMeter's HTTP Request sampler
References:
Docker Network
JMeter Distributed Testing with Docker

Deploy multiple application package on same container in vespa

I have downloaded sample vespa apps from git clone https://github.com/vespa-engine/sample-apps.git. I have created same application like basic-search which I named location. Now I want to deploy both application on same container using below steps:
To deploy basic-search application:
sudo docker run --detach --name vespa1 --hostname vespa-container --privileged --volume $VESPA_SAMPLE_APPS:/vespa-sample-apps --publish 8080:8080 vespaengine/vespa
sudo docker exec vespa1 bash -c 'curl --head http://localhost:19071/ApplicationStatus'
sudo docker exec vespa1 bash -c '/opt/vespa/bin/vespa-deploy prepare /vespa-sample-apps/basic-search/src/main/application/ && /opt/vespa/bin/vespa-deploy activate'
curl -s --head http://localhost:8080/ApplicationStatus
To deploy location application:
sudo docker run --detach --name vespa2 --hostname vespa-container --privileged --volume $VESPA_SAMPLE_APPS:/vespa-sample-apps --publish 8081:8081 vespaengine/vespa
sudo docker exec vespa2 bash -c 'curl --head http://localhost:19071/ApplicationStatus'
sudo docker exec vespa2 bash -c '/opt/vespa/bin/vespa-deploy prepare /vespa-sample-apps/location/src/main/application/ && /opt/vespa/bin/vespa-deploy activate'
curl -s --head http://localhost:8081/ApplicationStatus
First application is deployed successfully but in second one I am getting this error: Command failed. No directory or zip file found: '/vespa-sample-apps/location/src/main/application/'
To deploy second application, I need to publish it with 8081|8080. Because vespa-container is running on 8080 and I was trying to running on 8081 port.After running with 8081 on localhost and vespa-container on 8080 it works.Now I am able to deploy multiple apllications with multiple ports.
To make this work you'd need to assign different ports to all the processes of each of the applications using the "baseport" concept. However, it is much simpler to use different Docker containers for different applications instead. This also provides the resource isolation you'll want between different applications.
Note that if it's really different functionality belonging to the same application you can set up multiple separate clusters in the same application (in the same services.xml file), or alternatively just add multiple schemas and so on to the same clusters.

Expose application that runs under a docker container

I'm trying to expose a nodejs application that runs under a docker
docker run -p 3005:3005 -p 5858:5858 -i -t -v /usuarios centos-nodejs:1.0 /bin/bash
after that command, I access my application
cd usuarios
node index
and then the application is running inside the docker container.
How can I expose a port to access in my browser something like localhost:5858/my_api_here
It seems a nodejs application is bound to localhost:5858 only inside a container. That's why you cannot access it via 127.0.0.1:5858 from the host. You need to find a way to bind it to 0.0.0.0:5858. After that you can access it on 127.0.0.1:5858 from the host.
Following the command below, it works
docker run -p 3005:3005 -p 5858:5858 -i -t -v C:\Users\lgermano\Documents
\Repositorios:/opt/rede/workspace centos-nodejs:1.0 /bin/bash

docker exposing multiple ports - not working

I have a docker image that on running executes the following script
java -jar myjar.jar & disown
python2.7 manage.py runserver 0.0.0.0:9999
the myjar.jar program exposes a webservice and listens to port 11111.
In my Docker file i expose these 2 ports like so:
EXPOSE 9999 11111
This is how i run the image:
docker run --rm -p 9999:9999 -p 11111:11111 myimage
I can access the python web process with the url localhost:9999/admin/.
When i try to access the java web service with curl localhost:11111/myservice?wsdl I get connection refused.
When i enter the container with a terminal using
docker exec -i -t <container_id> bash
and run curl localhost:11111/myservice?wsdl i get the wsdl content.
Where is my port binding going wrong? (or port exposing? or maybe the way i am running the jar file?)

Cannot access tomcat8 server running in docker container from host machine

I am trying to connect to a web app running on tomcat8 in a docker container.
I am able to access it from within the container doing lynx http://localhost:8080/myapp, but when I try to access it from the host I only get HTTP request sent; waiting for response.
I am exposing port 8080 in the Dockerfile, I am using sudo docker inspect mycontainer | grep IPAddress to get the ip address of the container.
The command I am using to run the docker container is this:
sudo docker run -ti --name myapp --link mysql1:mysql1 --link rabbitmq1:rabbitmq1 -e "MYSQL_HOST=mysql1" -e "MYSQL_USER=myuser" -e "MYSQL_PASSWORD=mysqlpassword" -e "MYSQL_USERNAME=mysqlusername" -e "MYSQL_ROOT_PASSWORD=rootpassword" -e "RABBITMQ_SERVER_ADDRESS=rabbitmq1" -e "MY_WEB_ENVIRONMENT_ID=qa" -e "MY_WEB_TENANT_ID=tenant1" -p "8080:8080" -d localhost:5000/myapp:latest
My Dockerfile:
FROM localhost:5000/web_base:latest
MAINTAINER "Me" <me#my_company.com>
#Install mysql client
RUN yum -y install mysql
#Add Run shell script
ADD run.sh /home/ec2-user/run.sh
RUN chmod +x /home/ec2-user/run.sh
EXPOSE 8080
ENTRYPOINT ["/bin/bash"]
CMD ["/home/ec2-user/run.sh"]
My run.sh:
sudo tomcat8 start && sudo tail -f /var/log/tomcat8/catalina.out
Any ideas why I can access it from within the container but not from the host?
Thanks
What does your docker run command look like? You still need to do -p 8080:8080. Expose in the dockerfile only exposes it for linked containers not to the host vm.
I am able to access the tomcat8 server from the host now. The problem was here:
sudo tomcat8 start && sudo tail -f /var/log/tomcat8/catalina.out
Tomcat8 must be started as a service instead:
sudo service tomcat8 start && sudo tail -f /var/log/tomcat8/catalina.out
Hit given command to find IP address of docker-machine
$ docker-machine ls
The output will be like :
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.100:2376 v1.10.3
Now run your application from host machine as : http://192.168.99.100:8080/myapp

Resources