Service inside container not receiving requests - python-3.x

I am running a container with :
docker run --env-file .env <container_id> -p 0.0.0.0:8080:8080
The service inside the container is a python flask service, built with the library connexion, and listening on 0.0.0.0:8080.
When I docker ls, the column PORTS shows 8080/tcp, and I am not able to request the service, eg from swagger.
How can I request the service successfully ? Is 8080/tcp in the PORTS column means that my container is not bind to any port on the host machine ?

Related

Unable to communicate between docker and external service

I have a docker container running in localhost:3000
Also, I have a node app running in localhost:8081
Now if I want to make post or get request from localhost:3000 to localhost:8001 its not working at all.
Now if run the service as a binary (not a docker file) on localhost:3000 the same API requests works.
How do I communicate if using docker?
Each container runs on it's own bridge network where localhost means the container itself.
To access the host, you can add the option --add-host=host.docker.internal:host-gateway to the docker run command. Then you can access the host using the host name host.docker.internal. I.e. if you have a REST service on the host, your URL would look something like http://host.docker.internal:8081/my/service/endpoint.
The name host.docker.internal is the common name to use for the host, but you can use any name you like.
You need docker version 20.10 for this to work.

Calling or communicating with docker container on one machine from other application not in docker container and in another machine

I have my docker container in one machine running say Machine A. I have another machine B which consists of a flask server. I would like to call/communicate with the docker container in machine A from my flask server in Machine B. I am not running my flask server inside any docker container. I am actually very new to docker so I am not sure whether we are able to achieve it or not.
I am not sure what you want to do with your docker container from the flask server, but I am assuming that it would be an API or some service running in the docker container which you want to use in the flask server. You can do so by using the IP of machine A on which docker container is running, also, you will need to bind your docker container's port to the host machine's ( machine A) port. So that whenever you try to reach the host machine on that specific port, you will be calling the containers port instead.
If you want to execute a command in the running container then there are 2 ways to do so, first, you can SSH to the container, second you can SSH to the host machine and then use docker exec. But since you are trying to communicate from a flask server, I think that this might not be the case.
You can just directly visit the http service in container from other machine.
E.g.
Container on machineA was this:
docker run -idt -p 9000:80 nginx
Then, you machineB's flask application, you can just use:
requests.get("http://your_machine_a_ip:9000")
to get what you need.
Just remember, for container, you need to expose http port to host, so other machine could visit it.

Can not access Nodejs app which deployed on container of Bluemix

I create an image from cf ic command line expose 4000 then install nodejs,npm via apt-get and deploy a nodejs app on the image listen on port 4000.
And then I create a container with this image ,assign a public_ip to this container and run it.
But I found that I can not access the nodejs app with port [ http://public_ip4000 ].
When I login into container with command line cf ic exec -it container_id bash,I found that the nodejs app is running and I can access nodejs app by curl -GET http://localhost:4000/
Error Message is :net::ERR_CONNECTION_TIMED_OUT
Q: How can I access my nodejs app outside container?
Port 4000 is not exposed to the IBM Containers firewall.
There is a limited set of ports exposed, so I suggest you try a different port like 3000 or 5000. The complete list is not published for security reasons.
Alternatively you can create a Container Group with a single container. In that case you can define a route (domain) for your container that will automatically route all requests internally to your container port (like 4000).
You can find more details about creating container groups in Bluemix documentation:
https://console.ng.bluemix.net/docs/containers/container_creating_ov.html#container_group_ov

docker connection refused nodejs app

I launch docker container:
docker run --name node-arasaac -p 3000:3000 juanda/arasaac
And my node.js app works ok.
If I want to change host port:
docker run --name node-arasaac -p 8080:3000 juanda/arasaac
Web page is not loaded, logs from browser console:
Failed to load resource: net::ERR_CONNECTION_REFUSED
http://localhost:3000/app.318b21e9156114a4d93f.js Failed to load resource: net::ERR_CONNECTION_REFUSED
Do I need to have the same port both in host and container? It seems it knows how to resolve http://localhost:8080 so it loads my website, but internal links in the webpage go to port 3000 and it's not as good :-(
When you are running your node.js app in a docker container it will only expose the ports externally that you designate with your -p (lowercase) command. The first instance with, "-p 3000:3000", maps the host port 3000 to port 3000 being exposed from within your docker container. This provides a 1 to 1 mapping, so any client that is trying to connect to your node.js service can do so through the HOST port of 3000.
When you do "-p 8080:3000", docker maps the host port of 8080 to the node.js container port of 3000. This means any client making calls to your node.js app through the host (meaning not within the same container as your node.js app or not from a linked or networked docker container) will have to do so through the HOST port of 8080.
So if you have external services that expect to access your node.js at port 3000 they won't be able.

External access to Node.JS app, within Docker container

i have a Node app running within a Docker container, hosted on Elastic Beanstalk (single instance). The docker has port 3000 exposed to access the app within the docker, and I can 'curl 172.17.0.32:3000/test' from the host which returns the expected response.
The problem I have is accessing this port externally using the elastic beanstalk url. i.e
http://XXXXXX-env.elasticbeanstalk.com:3000/test
This will time out.. can anyone recommend how to gain access to this port externally?
thanks
Check this for reference
http://victorlin.me/posts/2014/11/26/running-docker-with-aws-elastic-beanstalk
see what your docker ps command returns.
The ip you have shared looks like private ip address of the docker service used for internal network. You have to enable a bridge between your host and docker container by supplying -p 3000:3000 to the run command and finally enable the app in your elastic console.

Resources