Docker and Spring boot: how to hide port from url? - nginx

I try to deploy my Spring Boot on DigitalOcean. I built docker image and run it on server and everything is fine (docker run -p 8080:8080 hub_user/docker_image). I have my own domain and ip address (access url to my application is myapp.com:8080). But how I can hide port number from url to access my application? How I can use my domain without port 8080?

If you are using http, what I suppose, the default port is the 80. So if you write myapp.com is equivalent to myapp.com:80.
docker run -p 80:8080 hub_user/docker_image

This isn't really a docker question per se. As AxelWass says, port 80 is the default port that HTTP uses (browsers automatically try and go here when you visit your site myapp.com). Your application is actually running inside the container on port 8080, so if you just map 8080:8080 then docker will forward traffic coming to your host on port 8080 (the first one) to 8080 (the second one) inside your container.
Now, if you want traffic coming to the server on port 80 (which all web traffic will by default) to be forwarded to your container, you need to map it like 80:8080.

Related

How to access the application from other device in local network

In the project I am working on, there is an application that works on many docker containers. To access one of the containers I need to add the following path in the /etc/hosts file
127.0.0.1 my.domain.com
Then App of course is available on http://my.domain.com in my computer.
Unfortunately, This is large complicated application and I cannot change the configuration to add a port (then i would use 192.168.X.X:PORT from other device)? so How I would to be able to access the application from other device in local network (WIFI or other way)? I try using localtunnel or ngrok but this works too slow and aren't good in this case.
Maybe someone knows another way?
If your server is running on ip 192.168.X.X on you local network, adding the line:
192.168.X.X my.domain.com
to the second device on your network should do the job
Another solution is to run a proxy server on the same instance as your server and send all the requests to the proxy server. The proxy server will listen on another port but it will forward all the requests to my.domain.com with the original port, it will work since it uses the same /etc/hosts.
try using nginx-webserver proxy it's free version it offers the feature what you want.
add a reverse proxy and host your app with my.domain.com
OR
Host your app on port :80 ie. the default port

Unable to access the JFrog Artifactory running as Docker container on Google Cloud

I have a VM running on GCP and got my docker installed on it. I have NGINX web server running on it with a static reserved external/public IP address. I can easily access this site by the public IP address. Now, I have my Artifactory running on this VM as a Docker container and the whole idea is to access this Docker container (Artifactory to be precise) using the same public IP address with a specific port, say 8081. I have configured the reverse proxy in the NGINX web server to bypass the request to the internal IP address of my docker container of Artifactory but the request is not reaching to it and cannot access the Artifactory.
Docker container is running:-
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a4119d923hd8 docker.bintray.io/jfrog/artifactory-pro:latest "/entrypoint-artifac…" 57 minutes ago Up 57 minutes 0.0.0.0:8081->8081/tcp my-app-dev-artifactory-pro
Here are my reverse proxy settings:-
server {
listen 81;
listen [::]:81;
server_name [My External Public IP Address];
location / {
proxy_pass https://localhost:8081;
}
}
Since you are using GCP to run this, I think that your issue is very simple. First, you do not have to have an Nginx in order to get to Artifactory inside a Docker container. You should be able to reach it very easily using the IP and port (for example XX.XX.XX.XX:8081) and I can see that in the Nginx configuration you are listening to port 81 which is not in use by Artifactory. I think that the issue here is either you did not allow HTTP communication to your GCP instance in the instance configuration, or you did not map the port in the "docker run" command.
You can see if the port is mapped by running the command "docker ps" and see if in the "PORTS" section there are ports that are mapped. If not, you will need to map the port (8081 to 8081) and make sure you GCP instance have HTTP traffic enabled, then you will be able to get to Artifactory with IP:PORT.

Running docker container at specific URL(s)

Just started implementing docker containers, I'm not sure if it is possible or not yet. Is it possible to publish a docker container based on URL or at specific host header? For example, two containers running at port 192.168.1.2 and port 80 but the first container has website abc.com and the second container has website xyz.com.
Can we use some reverse proxy server e.g. NGINX (or any other that you suggest) to direct web request to respective docker container?
No, you can't have "two containers running at IP 192.168.1.2 and port 80", but you can have a reverse-proxy running at IP 192.168.1.2 and port 80 and route to containers running at different IP+port.
Yes, you could do that, you can run a nginx container (or in the host) and it will redirect the content to the right container using the requested server name.
You can map the nginx 80 port in the nginx container to the host and link the others containers to it and then configurate nginx to do the proxy.
Here is a post about how to do it:
http://www.yannmoisan.com/docker.html
If you want to generate nginx configuration dynamically when you start/stop docker containers, you can consider using jwilder/nginx-proxy project. This will give you more flexibility when deciding your domains.

Expose my docker container to my external IP on GCP

We have a dockerized app that we imported on a Compute Engine instance with ubuntu 16.04.
It contains a nginx reverse proxy running on port 80 and in /etc/hosts we've added 127.0.0.1 mydockerizedapp
The GCE got an external IP address.
How can I set so that when I go on this external IP from a browser, I see the files served by the container nginx ?
You have to expose the ports of your container on the host machine by mapping it.
If you use the cli: --port-mappings=80:80:TCP

Unable to access web application in Docker container via container's ip and exposed port over http

I have a docker container running on a Centos host and has a host port: container port mapping. The docker container has an web application running.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a2f8ce62bb69 image1 "/bin/bash" 16 hours ago Up 16 hours 22/tcp, 0.0.0.0:7001->7001/tcp nostalgic_elion
I can access the application over http by host IP address and host port which is mapped. However if I replace the host IP with container IP, then I get an error saying "site cannot be reached" ERR_CONNECTION_TIMED_OUT.
Is it possible to access using the container IP and exposed port over http? Unfortunately I do not have much background on networking.
By default Docker containers can make connections to the outside world, but the outside world cannot connect to containers. (https://docs.docker.com/v1.7/articles/networking/)
The docs however, say it is possible to have outside world talk to containers with some extra run options. The docs say about using the run with options -P or ----publish-all=true|false. Refer the options in the same docker networking page.
If your only need is to share different ip address to teams. update your host file with the docker containers ip address - localhost
My /etc/hosts file:
container-ip localhost
container-ip localhost
container-ip localhost

Resources