Running docker shiny app on my own domain - linux

I have a VPS Linux (Ubuntu) server with specific IP and I would like to run my shiny app on my own domain http://my_domain.com. Therefore, I have built a docker container and I have run my app on the Ubuntu terminal:
sudo docker run -rm -p 4096:4096 my_app
It works well on the localhost. Then, I have modified the following lines in my Dockerfile:
EXPOSE 80
CMD ["R", "-e", "shiny::runApp('/srv/shiny-server/my_app/app', host = 'server_ip', port = 80)"]
I have built and run my docker container again and I have got the following error:
sudo docker run --rm -p 80:80 my_app
Listening on http://server_ip:80
createTcpServer: address not available
Error in initialize(...) : Failed to create server
Maybe I need to configure nginx. I would be grateful if someone could tell me what would be the best solution to run my app on my own domain and how to do it.

Docker container does not have access to server_ip, try this :
EXPOSE 80
CMD ["R", "-e", "shiny::runApp('/srv/shiny-server/my_app/app', host = '0.0.0.0', port = 80)"]

Related

Accessing docker container running in remote linux machine from a windows browser

I have a remote ubuntu machine with docker installed and a container is running on that, i want to access it from my windows machine through a browser, i can connect to the ubuntu remote machine from my windows machine through putty, is there any way, i would be able to achieve this, any helps or leads in this case will be highly appreciated?
When you start the container, you'll need to publish the port that you want to connect to using the -p flag. Here's an example from the Docker documentation that publishes port 80 in the container to port 80 on the host (you can map to a different port if you'd like):
$ docker run -d -p 80:80 my_image service nginx start
See https://docs.docker.com/engine/reference/run/#expose-incoming-ports

What is port 49160 in docker-run?

I am following this tutorial to set up docker for my node.js rest api and there is this line in the tutorial:
docker run -p 49160:8080 -d <your username>/node-web-app
And this description:
The -p flag redirects a public port to a private port inside the
container. Run the image you previously built:
From the description, I know that port 49160 is a public port and 8080 is a private port. Since I am exposing port 5001 in my nodejs app, so I think I am running:
docker run -p 49160:5001 -d <your username>/node-web-app
But what exactly is a public port? Why is it "49160"?
It can be anything. Tutorial just used a random port. You can change it whatever you want. Then you can access your node-web-app running inside container at port 5001 at localhost:49160 from your host machine.
In your example port 8080 leads to some server (probably web server / Node) located inside of your Docker container. The outside (the host you're working on) port is 49160. The Docker setting named -p connects the inner port 8080 to the outer port 49160. If you now open the browser in your host system and hit the url http://localhost:49160 you will essentially access port 8080 inside the container.
Port 8080 is usually used for web servers. It is not obligatory though.
Port 49160 is just some port you or the auther of the tutorial decided to take as an example.
If you have a server inside the container listening on port 5001 it will not be accessible in your setup. If you want to make it accessible, you could adapt the following command:
docker run -p 49160:8080 -p 49159:5001 -d <your username>/node-web-app

How to access Linux Docker Container's TCP Port from windows 10 host

I have installed Docker for windows on windows 10 . I am running Linux containers on docker. I have a python app which has ZeroMQ which has a zmq server listening on port 3000 . I want to send images from my c# app deployed on windows host to connect to the zmq app running on docker linux containers and send images through tcp using zeromq .
I am unable to access the container tcp port from windows app .
Please advise .
I tried the below:
C:\Windows\system32>docker run -p 3000:3000 server-zmq10 docker:
Error response from daemon:
driver failed programming external connectivity on endpoint condescending_kilby
(fc383d60832ae98a5601ba62e215a4033936f74b64577ca6b14f7c47f1f27f9a): Error starting
userland proxy: mkdir /port/tcp:0.0.0.0:3000:tcp:172.17.0.2:3000: input/output error.
Python code:
context = zmq.Context()
socket = context.socket(zmq.REP)
print('Binding to port 3000')
socket.bind("tcp://127.0.0.1:3000")
I have done on the DockerFIle when creating the image:
EXPOSE 3000
Is there anything else which is required here ?
After exposing 3000 port is there any service running for listening?
or use -p 5000:5000 in docker run command

Docker - Using localhost for to access running container

This command below:
docker run -p 8000:8000 -t panels2
Which I am running should apparently allow me to run my application localhost on port 8000 locally.
In the docker terminal when running ‘docker ps’ I see:
0.0.0.0:8000->8000/tcp
Dockerfile look this:
EXPOSE 8000
ENTRYPOINT ["/usr/bin/python3.6", "/app/manage.py", "runserver"]
How to get access to localhost:8000?
The answer is set ip on 0.0.0.0 not 127.0.0.1(work inside container) because when we create a bridge then automatically ports are mapping on 0.0.0.0 ip even if we set 127.0.0.1 for application.

Exposing a Docker container port

I have been trying to connect to a docker container via ip, but reamins unsuccessful. When I used "docker inspect container-id" I get this result.
My virtual box settings are by default:
Can someone help me resolving this issue?
When running docker, you can specify which port(s) you'd like to be accessible to the outside world. Basic syntax is:
docker run -p hostPort:containerPort imageName
or just
docker run -p hostPort imageName
In the first case, externally, hostPort will be used, but inside the container: containerPort will be used. In the second instance, you'd just be using that port both inside and outside your container.
You can also create an image with ports exposed by using the EXPOSE command in a Dockerfile.
You need to perform port forwarding or just simply expose port.
Port Forwarding:
docker run -p 2022:22 -p 2375:2375
Expose Port:
docker run -p 22 -p 2375

Resources