I have created a docker image for deployment of microservice.
I am right now testing ti by trying to deploy on my local machine.
The docker container ogt created successfully and I am getting started application
o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-10-25 12:41:53.867 INFO [] 1 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2019-10-25 12:41:53.901 INFO [] 1 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2019-10-25 12:41:53.949 INFO [] 1 --- [ main] s.d.s.w.s.ApiListingReferenceScanner : Scanning for api listing references
2019-10-25 12:41:54.230 INFO [] 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
But when I try to hit any rest service like so localhost:8080/myApi/test
It gives me error
localhost refused to connect.
Search Google for localhost 8080 payment
ERR_CONNECTION_REFUSED
What could possibly be going wrong ?
Checking list of running images docker ps gives me an entry with empty port details .Could this be the reason ?
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2feab85c47db test_3 "java -Dserver.port=…" 18 minutes ago Up 18 minutes wizardly_leavitt
To access services inside containers you need to forward host ports to container ports.
It can be done with -p HOST_PORT:CONTAINER_PORT parameter in the command line.
docker run -it -p 8080:8080 test_3
REF: https://docs.docker.com/config/containers/container-networking/
Related
When I run the command:
docker run -d -p 8080:3100 username/sb-dockerized
and go to localhost:8080, it doesn't connect. Says "This page isn't working"
In my Dockerfile I am exposing port 3100
EXPOSE 3100
Logs
2021-07-10 15:53:27.828 INFO 1 --- [ main] c.e.s.SpringBootDockerizedApplication : Starting SpringBootDockerizedApplication v0.0.1-SNAPSHOT using Java 15.0.1 on d3b451475e8d with PID 1 (/clancinio/lib/sb-dockerized.jar started by root in /clancinio/lib)
2021-07-10 15:53:27.832 INFO 1 --- [ main] c.e.s.SpringBootDockerizedApplication : No active profile set, falling back to default profiles: default
2021-07-10 15:53:29.556 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-07-10 15:53:29.579 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-07-10 15:53:29.579 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.48]
2021-07-10 15:53:29.679 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-07-10 15:53:29.679 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1755 ms
2021-07-10 15:53:30.300 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-07-10 15:53:30.316 INFO 1 --- [ main] c.e.s.SpringBootDockerizedApplication : Started SpringBootDockerizedApplication in 3.173 seconds (JVM running for 3.872)
Any idea of what could be going wrong?
In your Dockerfile, EXPOSE 8080 because your spring-boot app is listening to that port inside your container. While running, run with docker run -d -p <<the port you want to hit in the url>>:8080 username/sb-dockerized and then access http://localhost:<<the port you want to hit in the url>>
From your browser navigate to http://<hostIP>:8080
I have created a docker network with:
docker network create --driver bridge sample-network
Next I start two containers on that network:
docker run -it --network sample-network -p 8080:8080 --name frontend-container frontend-image
docker run -it --network sample-network -p 8082:8080 --name backend-container backend-image
and the result:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e5328faa21db frontend-image "docker-entrypoint.s…" 33 minutes ago Up 33 minutes 0.0.0.0:8080->8080/tcp frontend-container
e13d798edbec backend-image "java -jar backend-0…" About an hour ago Up About an hour 0.0.0.0:8082->8080/tcp backend-container
Where the backend-container runs a spring boot web application
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.7.RELEASE)
2019-10-21 18:29:40.487 INFO 1 --- [ main] hello.Application : Starting Application v0.1.0-SNAPSHOT on e13d798edbec with PID 1 (/backend-0.1.0-SNAPSHOT.jar started by root in /)
2019-10-21 18:29:40.489 INFO 1 --- [ main] hello.Application : No active profile set, falling back to default profiles: default
2019-10-21 18:29:41.289 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-10-21 18:29:41.321 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-10-21 18:29:41.321 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.22]
2019-10-21 18:29:41.399 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-10-21 18:29:41.399 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 873 ms
2019-10-21 18:29:41.609 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-10-21 18:29:41.758 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-10-21 18:29:41.761 INFO 1 --- [ main] hello.Application : Started Application in 1.604 seconds (JVM running for 1.889)
Next I would like to curl the backend-container from the frontend-container:
$ docker exec -it frontend-container /bin/bash
bash-4.4# curl backend-container:8082
curl: (7) Failed to connect to backend-container port 8082: Connection refused
But why do I get a connection refused? They are both on the same network.
Both of your containers run applications on port 8080. So to connect to the backend application over your network you should use backend-container:8080 as host.
It seems that you published port 8082 of backend-container to your host - but that does not mean that you can connect to app on this port from another container - it would work if you wanted to access backend-container from host using localhost:8082.
On how -p option works refer to container networking :
By default, when you create a container, it does not publish any of its ports to the outside world. To make a port available to services outside of Docker, or to Docker containers which are not connected to the container’s network, use the --publish or -p flag. This creates a firewall rule which maps a container port to a port on the Docker host.
I want to run this docker hub image locally: https://hub.docker.com/r/jhipster/jhipster-sample-app (which normally runs with a npm start and gradlew) in W10home using Docker ToolBox (and it works fine)
I followed the instructions at: https://www.jhipster.tech/docker-compose/
and try to run a: $ docker-compose -f jhipster-sample-app/prod.yml up , but it gives me this error (although the image is there):
usuario#DESKTOP-GTCQCAR MINGW64 /c/Program Files/Docker Toolbox
$ docker-compose -f jhipster-sample-app/prod.yml up
ERROR: .FileNotFoundError: [Errno 2] No such file or directory: '.\\jhipster-sample-app/prod.yml'
NOTE: I also tried changing the tag, but with the same result. Why is it not finding the image that is for sure there?
I also tried to Quick launch: Run a simple jhipster application directly with Docker, in development profile: $ docker container run -d -p 8080:8080 -e SPRING_PROFILES_ACTIVE=dev jhipster/jhipster-sample-app
But, I could not access to the application at http://localhost:8080 (though the container is created and running).
I even try to run it: $ docker run jhipster/jhipster-sample-app getting this error:
2019-01-31 09:33:05.215 INFO 1 --- [ main]
i.g.j.s.JhipsterSampleApplicationApp : Starting JhipsterSampleApplicationApp on 596e926cb096 with PID 1 (/app.war started by root in /)
2019-01-31 09:33:05.252 INFO 1 --- [ main] i.g.j.s.JhipsterSampleApplicationApp : The following profiles are active: prod
2019-01-31 09:33:37.773 ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : Hikari - Exception during pool initialization.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
But I can run other images like $ docker run hello-world
So I feel kind of lost here and I do not know what I'm doing wrong. Thanks all! I'm new to Docker.
To run https://hub.docker.com/r/jhipster/jhipster-sample-app, you need to start the other containers such as the database. These are not packaged in the app container.
git clone https://github.com/jhipster/jhipster-sample-app.git
cd jhipster-sample-app
docker-compose -f src/main/docker/app.yml up -d
This will load the config from app.yml and start both the app and database containers.
Installed Docker on Mac and trying to run Vespa on Docker following steps specified in following link
https://docs.vespa.ai/documentation/vespa-quick-start.html
I did n't had any issues till step 4. I see vespa container running after step 2 and step 3 returned 200 OK response.
But Step 5 failed to return 200 OK response. Below is the command I ran on my terminal
curl -s --head http://localhost:8080/ApplicationStatus
I keep getting
curl: (52) Empty reply from server whenever I run without -s option.
So I tried to see listening ports inside my vespa container and don't see anything for 8080 but can see for 19071(used in step 3)
➜ ~ docker exec vespa bash -c 'netstat -vatn| grep 8080'
➜ ~ docker exec vespa bash -c 'netstat -vatn| grep 19071'
tcp 0 0 0.0.0.0:19071 0.0.0.0:* LISTEN
Below doc has info related to vespa ports
https://docs.vespa.ai/documentation/reference/files-processes-and-ports.html
I'm assuming port 8080 should be active after docker run(step 2 of quick start link) and can be accessed outside container as port mapping is done.
But I don't see 8080 port active inside container in first place.
A'm I missing something. Do I need to perform any additional step than mentioned in quick start? FYI I installed Jenkins inside my docker and was able to access outside container via port mapping. But not sure why it's not working with vespa.I have been trying from quiet sometime but no progress. Please advice me if I'm missing something here.
You have too low memory for your docker container, "Minimum 6GB memory dedicated to Docker (the default is 2GB on Macs).". See https://docs.vespa.ai/documentation/vespa-quick-start.html
The deadlock detector warnings and failure to get configuration from configuration server (which is likely oom killed) indicates that you are too low on memory.
My guess is that your jdisc container had not finished initialize or did not initialize properly? Did you try to check the log?
docker exec vespa bash -c '/opt/vespa/bin/vespa-logfmt /opt/vespa/logs/vespa/vespa.log'
This should tell you if there was something wrong. When it is ready to receive requests you would see something like this:
[2018-12-10 06:30:37.854] INFO : container Container.org.eclipse.jetty.server.AbstractConnector Started SearchServer#79afa369{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
[2018-12-10 06:30:37.857] INFO : container Container.org.eclipse.jetty.server.Server Started #10280ms
[2018-12-10 06:30:37.857] INFO : container Container.com.yahoo.container.jdisc.ConfiguredApplication Switching to the latest deployed set of configurations and components. Application switch number: 0
[2018-12-10 06:30:37.859] INFO : container Container.com.yahoo.container.jdisc.ConfiguredApplication Initializing new set of configurations and components. Application switch number: 1
I'm running a spring boot application in the background as an API server, but I cannot access it from localhost:8080.
Container status
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2c494c8304e0 corpobids.com/server:latest "java -jar server.jar" 5 seconds ago Up 4 seconds 0.0.0.0:8080->8080/tcp, 0.0.0.0:18080->18080/tcp server_api-server_1
8d1883ebcb0b postgres:9.6 "docker-entrypoint.s…" 5 seconds ago Up 4 seconds 0.0.0.0:5432->5432/tcp server_database-server_1
The ports are already exposed and mapped. The application is running fine in the container.
2018-10-31 15:25:21.255 INFO 1 --- [ main]
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s):
8080 (http) with context path ''
2018-10-31 15:25:21.256 INFO 1 --- [ main]
com.api.server.Application : Started Application in
13.861 seconds (JVM running for 14.25)
How do I call the API of the application from my host computer?