Unable to cUrl docker container - docker

I am following the tutorial https://docker-curriculum.com/ and running the ElasticSearch image on Windows 10. But the curl is not responding to the default url the is mentioned while running the docker image.
Any help is appreciated.
I ran the following commands.
$ docker pull docker.elastic.co/elasticsearch/elasticsearch:6.3.2
$ docker run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.3.2
e8be84174fec0bcb796265d93e67ec70b6ac77a54a4ff65be7a51f9a64037f43
Listed the containers
docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
572b79717617 docker.elastic.co/elasticsearch/elasticsearch:6.3.2 "/usr/local/bin/dock…" 12 hours ago Up 12 hours 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp es
9ff0b5b40306 acerab/foodtrucks-web "bash" 14 hours ago Up 14 hours 5000/tcp
Listed the Elastic Search Container container es logs
$ docker container logs es
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[2023-01-19T03:57:00,940][INFO ][o.e.n.Node ] [] initializing ...
[2023-01-19T03:57:01,007][INFO ][o.e.e.NodeEnvironment ] [-dsoNEx] using [1] data paths, mounts [[/ (overlay)]], net usable_space [233.8gb], net total_space [250.9gb], types [overlay]
[2023-01-19T03:57:01,007][INFO ][o.e.e.NodeEnvironment ] [-dsoNEx] heap size [989.8mb], compressed ordinary object pointers [true]
[2023-01-19T03:57:01,010][INFO ][o.e.n.Node ] [-dsoNEx] node name derived from node ID [-dsoNExNSMmYeeQDYc3-Og]; set [node.name] to override
[2023-01-19T03:57:01,010][INFO ][o.e.n.Node ] [-dsoNEx] version[6.3.2], pid[1], build[default/tar/053779d/2018-07-20T05:20:23.451332Z], OS[Linux/5.10.102.1-microsoft-standard-WSL2/amd64], JVM["Oracle Corporation"/OpenJDK 64-Bit Server VM/10.0.2/10.0.2+13]
[2023-01-19T03:57:01,010][INFO ][o.e.n.Node ] [-dsoNEx] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch.mV5lGAl6, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m, -Djava.locale.providers=COMPAT, -XX:UseAVX=2, -Des.cgroups.hierarchy.override=/, -Des.path.home=/usr/share/elasticsearch, -Des.path.conf=/usr/share/elasticsearch/config, -Des.distribution.flavor=default, -Des.distribution.type=tar]
[2023-01-19T03:57:03,139][INFO ][o.e.p.PluginsService ] [-dsoNEx] loaded plugin [ingest-user-agent]
[2023-01-19T03:57:06,403][INFO ][o.e.x.s.a.s.FileRolesStore] [-dsoNEx] parsed [0] roles from file [/usr/share/elasticsearch/config/roles.yml]
[2023-01-19T03:57:06,987][INFO ][o.e.x.m.j.p.l.CppLogMessageHandler] [controller/118] [Main.cc#109] controller (64 bit): Version 6.3.2 (Build 903094f295d249) Copyright (c) 2018 Elasticsearch BV
[2023-01-19T03:57:07,660][INFO ][o.e.d.DiscoveryModule ] [-dsoNEx] using discovery type [single-node]
[2023-01-19T03:57:08,732][INFO ][o.e.n.Node ] [-dsoNEx] initialized
[2023-01-19T03:57:08,732][INFO ][o.e.n.Node ] [-dsoNEx] starting ...
[2023-01-19T03:57:08,944][INFO ][o.e.t.TransportService ] [-dsoNEx] publish_address {172.17.0.2:9300}, bound_addresses {0.0.0.0:9300}
[2023-01-19T03:57:08,962][WARN ][o.e.b.BootstrapChecks ] [-dsoNEx] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2023-01-19T03:57:08,998][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [-dsoNEx] publish_address {172.17.0.2:9200}, bound_addresses {0.0.0.0:9200}
[2023-01-19T03:57:08,999][INFO ][o.e.n.Node ] [-dsoNEx] started
But when I run CUrl, I am not able to connect.
$ curl 0.0.0.0:9200
When I issue the cUrl on 127.0.0.2.9200, I see the response
curl 127.0.0.2:9200
StatusCode : 200
StatusDescription : OK
Content : {
"name" : "-dsoNEx",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "UzUGppOxQ5ePcxLNB49HvA",
"version" : {
"number" : "6.3.2",
"build_flavor" : "default",
"build_type" : "ta...
RawContent : HTTP/1.1 200 OK
Content-Length: 494
Content-Type: application/json; charset=UTF-8
{
"name" : "-dsoNEx",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "UzUGppOxQ5ePcxLNB49HvA",
"vers...
Forms : {}
Headers : {[Content-Length, 494], [Content-Type, application/json; charset=UTF-8]}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : mshtml.HTMLDocumentClass
RawContentLength : 494

Connecting to 0.0.0.0 does not make any sense, as it is not the address of your device. The 0.0.0.0:9200->9200/tcp output from docker means that the service is listening on all interfaces (i.e., 0.0.0.0). Thus you can connect via 127.0.0.1 or your public IP address from your network card, for instance.

Related

Docker image ran successfully but application didn't run

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/

Curl application running in a container from another container

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.

Unable to access elasticsearch running in docker on mac OS X

I went through this SO ques but still couldn't make it work. I followed this elasticsearch tutorial to run it in dev mode with:
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.2.4
Elasticsearch starts but still I am unable to reach it with curl or browser. These are the logs:
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node"
docker.elastic.co/elasticsearch/elasticsearch:6.2.4
[2018-06-08T08:35:59,131][INFO ][o.e.n.Node ] [] initializing ...
[2018-06-08T08:35:59,209][INFO ][o.e.e.NodeEnvironment ] [vMpk2HC] using [1] data paths, mounts [[/ (overlay)]], net usable_space [31.7gb], net total_space [37.2gb], types [overlay]
[2018-06-08T08:35:59,209][INFO ][o.e.e.NodeEnvironment ] [vMpk2HC] heap size [1007.3mb], compressed ordinary object pointers [true]
[2018-06-08T08:35:59,211][INFO ][o.e.n.Node ] node name [vMpk2HC] derived from node ID [vMpk2HCTQNKxTMFmkE-0oA]; set [node.name] to override
[2018-06-08T08:35:59,211][INFO ][o.e.n.Node ] version[6.2.4], pid[1], build[ccec39f/2018-04-12T20:37:28.497551Z], OS[Linux/4.9.0-0.bpo.2-amd64/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_161/25.161-b14]
[2018-06-08T08:35:59,212][INFO ][o.e.n.Node ] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch.muZEBoID, -XX:+HeapDumpOnOutOfMemoryError, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Des.cgroups.hierarchy.override=/, -Des.path.home=/usr/share/elasticsearch, -Des.path.conf=/usr/share/elasticsearch/config]
[2018-06-08T08:36:01,407][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded module [aggs-matrix-stats]
[2018-06-08T08:36:01,407][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded module [analysis-common]
[2018-06-08T08:36:01,407][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded module [ingest-common]
[2018-06-08T08:36:01,407][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded module [lang-expression]
[2018-06-08T08:36:01,407][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded module [lang-mustache]
[2018-06-08T08:36:01,407][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded module [lang-painless]
[2018-06-08T08:36:01,408][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded module [mapper-extras]
[2018-06-08T08:36:01,408][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded module [parent-join]
[2018-06-08T08:36:01,408][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded module [percolator]
[2018-06-08T08:36:01,408][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded module [rank-eval]
[2018-06-08T08:36:01,408][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded module [reindex]
[2018-06-08T08:36:01,408][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded module [repository-url]
[2018-06-08T08:36:01,408][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded module [transport-netty4]
[2018-06-08T08:36:01,408][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded module [tribe]
[2018-06-08T08:36:01,409][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded plugin [ingest-geoip]
[2018-06-08T08:36:01,409][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded plugin [ingest-user-agent]
[2018-06-08T08:36:01,409][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded plugin [x-pack-core]
[2018-06-08T08:36:01,409][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded plugin [x-pack-deprecation]
[2018-06-08T08:36:01,409][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded plugin [x-pack-graph]
[2018-06-08T08:36:01,410][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded plugin [x-pack-logstash]
[2018-06-08T08:36:01,410][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded plugin [x-pack-ml]
[2018-06-08T08:36:01,410][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded plugin [x-pack-monitoring]
[2018-06-08T08:36:01,410][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded plugin [x-pack-security]
[2018-06-08T08:36:01,410][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded plugin [x-pack-upgrade]
[2018-06-08T08:36:01,410][INFO ][o.e.p.PluginsService ] [vMpk2HC] loaded plugin [x-pack-watcher]
[2018-06-08T08:36:05,966][INFO ][o.e.x.m.j.p.l.CppLogMessageHandler] [controller/104] [Main.cc#128] controller (64 bit): Version 6.2.4 (Build 524e7fe231abc1) Copyright (c) 2018 Elasticsearch BV
[2018-06-08T08:36:06,529][INFO ][o.e.d.DiscoveryModule ] [vMpk2HC] using discovery type [single-node]
[2018-06-08T08:36:07,313][INFO ][o.e.n.Node ] initialized
[2018-06-08T08:36:07,313][INFO ][o.e.n.Node ] [vMpk2HC] starting ...
[2018-06-08T08:36:07,457][INFO ][o.e.t.TransportService ] [vMpk2HC] publish_address {172.17.0.2:9300}, bound_addresses {0.0.0.0:9300}
[2018-06-08T08:36:07,488][WARN ][o.e.b.BootstrapChecks ] [vMpk2HC] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2018-06-08T08:36:07,520][INFO ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [vMpk2HC] publish_address {172.17.0.2:9200}, bound_addresses {0.0.0.0:9200}
[2018-06-08T08:36:07,520][INFO ][o.e.n.Node ] [vMpk2HC] started
[2018-06-08T08:36:07,698][INFO ][o.e.g.GatewayService ] [vMpk2HC] recovered [0] indices into cluster_state
[2018-06-08T08:36:08,241][INFO ][o.e.l.LicenseService ] [vMpk2HC] license [70cc45f9-4b48-4c75-a3db-9e469d607f3e] mode [basic] - valid
[2018-06-08T08:36:17,455][INFO ][o.e.c.m.MetaDataCreateIndexService] [vMpk2HC] [.monitoring-es-6-2018.06.08] creating index, cause [auto(bulk api)], templates [.monitoring-es], shards [1]/[0], mappings [doc]
[2018-06-08T08:36:17,751][INFO ][o.e.c.r.a.AllocationService] [vMpk2HC] Cluster health status changed from [YELLOW] to [GREEN] (reason: [shards started [[.monitoring-es-6-2018.06.08][0]] ...]).
I installed docker with homebrew using brew install docker docker-compose docker-machine xhyve docker-machine-driver-xhyve and elasticsearch with brew install elasticsearch
If I try to install elasticsearch with homebrew and start it on my local machine, it works. But docker container doesn't.
I am not sure what was the problem. But I uninstalled my docker and installed it again with the dmg file provided by docker.
It works now and I am finally able to access elasticsearch :)
Looks good to me, no errors in the logs. You need to connect using the IP address you can see in the logs and all will be fine
curl http://172.17.0.2:9200
If you log into the container, you can access your ES with curl http://localhost:9200, but since you're on the host, you need to use the IP address that the container published ES to.

How view solr logs from docker container

I want to view logs to check if a library is correct installed.
I use solr in a docker container.
How I can do that?
So, if you're using the official image, running it like this:
docker run --name my_solr -d -p 8983:8983 -t solr
you can see the logs with docker logs:
docker logs my_solr
These are my logs, for example:
Starting Solr 7.2.0
2018-01-10 11:05:29.618 INFO (main) [ ] o.e.j.s.Server jetty-9.3.20.v20170531
2018-01-10 11:05:30.570 INFO (main) [ ] o.a.s.s.SolrDispatchFilter ___ _ Welcome to Apache Solr™ version 7.2.0
2018-01-10 11:05:30.570 INFO (main) [ ] o.a.s.s.SolrDispatchFilter / __| ___| |_ _ Starting in standalone mode on port 8983
2018-01-10 11:05:30.570 INFO (main) [ ] o.a.s.s.SolrDispatchFilter \__ \/ _ \ | '_| Install dir: /opt/solr
2018-01-10 11:05:30.611 INFO (main) [ ] o.a.s.s.SolrDispatchFilter |___/\___/_|_| Start time: 2018-01-10T11:05:30.574Z
2018-01-10 11:05:30.662 INFO (main) [ ] o.a.s.c.SolrResourceLoader Using system property solr.solr.home: /opt/solr/server/solr
2018-01-10 11:05:30.735 INFO (main) [ ] o.a.s.c.SolrXmlConfig Loading container configuration from /opt/solr/server/solr/solr.xml
2018-01-10 11:05:31.280 INFO (main) [ ] o.a.s.c.SolrResourceLoader [null] Added 0 libs to classloader, from paths: []
2018-01-10 11:05:32.918 INFO (main) [ ] o.a.s.c.CorePropertiesLocator Found 0 core definitions underneath /opt/solr/server/solr
2018-01-10 11:05:33.108 INFO (main) [ ] o.e.j.s.Server Started #5029ms

ECS Agent starting Docker container doesn't complete. Manual start successful

I followed the ECS Getting Started tutorial but the ECS Agent isn't getting the container started. When I start the image manually on the same instance it starts fine.
The image is a Spring Boot web application with a single endpoint on / that returns the string "Hello world!!". The container runs fine locally, and also runs fine on a CentOS EC2 instance I've created. The endpoint is available publicly when I run the docker image on the CentOS EC2 instance.
The ECS Instance has security groups created by the wizard and has port 80 open. I added port 22 for SSH access.
When I SSH into the ECS instance to see the Docker logs for my container, and it looks like it's hanging during the entrypoint execution.
Here are the Docker logs for the hanging instance:
[ec2-user#ip-10-0-0-156 ~]$ docker logs --tail 100 107d4cf04dd8
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.2.RELEASE)
2016-11-25 17:36:22.505 INFO 1 --- [ main] ecstest.Application : Starting Application on 107d4cf04dd8 with PID 1 (/ecstest-1.0-SNAPSHOT.jar started by root in /)
2016-11-25 17:36:22.546 INFO 1 --- [ main] ecstest.Application : No active profile set, falling back to default profiles: default
2016-11-25 17:36:23.059 INFO 1 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#6d21714c: startup date [Fri Nov 25 17:36:23 UTC 2016]; root of context hierarchy
2016-11-25 17:36:30.972 INFO 1 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-11-25 17:36:31.014 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-11-25 17:36:31.016 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.6
2016-11-25 17:36:31.464 INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-11-25 17:36:31.464 INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 8458 ms
At first it seems like an application error in my container image, but when I stop the docker process and run the same image manually, the output is as expected and I can reach my endpoint from outside the instance as expected.
[ec2-user#ip-10-0-1-124 ~]$ docker stop -t 1 4d2401d7db93 && docker run -p 80:8080 -d ############.dkr.ecr.us-west-2.amazonaws.com/ecstest
4d2401d7db93
db8cffa89995401d9314d7d70e954f09c7fde972a5e6a423615827d8c47b9d10
[ec2-user#ip-10-0-1-124 ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
db8cffa89995 ############.dkr.ecr.us-west-2.amazonaws.com/ecstest "java -jar ecstest-1." 10 seconds ago Up 9 seconds 0.0.0.0:80->8080/tcp small_gates
85bd18480c99 amazon/amazon-ecs-agent:latest "/agent" 11 minutes ago Up 11 minutes ecs-agent
[ec2-user#ip-10-0-1-124 ~]$ docker logs --tail 1000 db8cffa89995
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.2.RELEASE)
2016-11-25 18:06:57.960 INFO 1 --- [ main] ecstest.Application : Starting Application on db8cffa89995 with PID 1 (/ecstest-1.0-SNAPSHOT.jar started by root in /)
2016-11-25 18:06:58.004 INFO 1 --- [ main] ecstest.Application : No active profile set, falling back to default profiles: default
2016-11-25 18:06:58.578 INFO 1 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#6d21714c: startup date [Fri Nov 25 18:06:58 UTC 2016]; root of context hierarchy
2016-11-25 18:07:05.784 INFO 1 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-11-25 18:07:05.866 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-11-25 18:07:05.876 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.6
2016-11-25 18:07:06.283 INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-11-25 18:07:06.283 INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 7753 ms
2016-11-25 18:07:07.026 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-11-25 18:07:07.031 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-11-25 18:07:07.031 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-11-25 18:07:07.032 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-11-25 18:07:07.033 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-11-25 18:07:08.432 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#6d21714c: startup date [Fri Nov 25 18:06:58 UTC 2016]; root of context hierarchy
2016-11-25 18:07:08.786 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[],methods=[GET]}" onto public java.lang.String ecstest.Application.get()
2016-11-25 18:07:08.800 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-11-25 18:07:08.801 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-11-25 18:07:09.036 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-11-25 18:07:09.036 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-11-25 18:07:09.204 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-11-25 18:07:09.893 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-11-25 18:07:10.201 INFO 1 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-11-25 18:07:10.216 INFO 1 --- [ main] ecstest.Application : Started Application in 14.385 seconds (JVM running for 16.522)
Any ideas why the ECS Agent isn't getting my application started?
Task Definition JSON
{
"attributes": null,
"requiresAttributes": [
{
"value": null,
"name": "com.amazonaws.ecs.capability.ecr-auth",
"targetId": null,
"targetType": null
}
],
"taskDefinitionArn": "arn:aws:ecs:us-west-2:############:task-definition/DcTaskDefinition:4",
"networkMode": "bridge",
"status": "ACTIVE",
"revision": 4,
"taskRoleArn": null,
"containerDefinitions": [
{
"volumesFrom": [],
"memory": 128,
"extraHosts": null,
"dnsServers": null,
"disableNetworking": null,
"dnsSearchDomains": null,
"portMappings": [
{
"hostPort": 80,
"containerPort": 8080,
"protocol": "tcp"
}
],
"hostname": null,
"essential": true,
"entryPoint": null,
"mountPoints": [],
"name": "DcContainer",
"ulimits": null,
"dockerSecurityOptions": null,
"environment": [],
"links": null,
"workingDirectory": null,
"readonlyRootFilesystem": null,
"image": "############.dkr.ecr.us-west-2.amazonaws.com/ecstest:latest",
"command": null,
"user": null,
"dockerLabels": null,
"logConfiguration": null,
"cpu": 0,
"privileged": null,
"memoryReservation": null
}
],
"placementConstraints": [],
"volumes": [],
"family": "DcTaskDefinition"
}
The memory key in the Task Definition JSON imposes a hard memory limit on the container. When a container tries to exceed that limit, the Docker daemon is supposed to kill it.
I'm not sure whether this can cause your container to get "stuck", however that's the only important difference I see between how your container runs when ECS runs it and how it runs from the command line.
So, I would try to set the memory value to at least 300, or use the memoryReservation key instead which imposes a soft memory limit.
More information on the difference between hard and soft memory limits can be found in the official ECS documentation.

Resources