Does anyone know how to point a docker container to ngrok? - docker

I have discourse which i installed through docker, however, i am trying to see if i can connect that through Ngrok. Anyone familiar with Ngrok?
The app is running through a docker container at localhost:9292
when i try to run ngrok it does not work.
ngrok http -host-header=rewrite localhost:9292

Answering my questions in hopes that i can help some else.
So when i installed discourse through docker, i had to ssh into my docker container. I then had to install nginx and config it to point my box IP address to my private network. Once i reload it work, however, I was getting a blank page when i hooked it to ngrok. SO....i had to turn off the security protocols in Chrome so that it allowed ngrok to display my app. Let me know if anyone have any questions and id love to expand on this.

this composer works for me
version: '3'
services:
yourwebserver:
build:
context: ./
dockerfile: ...
target: ...
container_name: yourwebserver
volumes:
- ...
ports:
- ...
extra_hosts:
- 'host.docker.internal:host-gateway'
depends_on:
- ngrok
ngrok:
image: ngrok/ngrok:alpine
environment:
NGROK_AUTHTOKEN: '...'
command: 'http yourwebserver:80'
ports:
- '4040:4040'
expose:
- '4040'

Related

Traefik with Docker-Compose not working as expected

I am fairly new to using traefik, so I might be totally missing something simple, but I have the following docker-compose.yaml:
version: '3.8'
services:
reverse-proxy:
container_name: reverse_proxy
restart: unless-stopped
image: traefik:v2.0
command:
- --entrypoints.web.address=:80
- --entrypoints.web-secure.address=:443
- --api.insecure=true
- --providers.file.directory=/conf/
- --providers.file.watch=true
- --providers.docker=true
ports:
- "80:80"
- "8080:8080"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./scripts/certificates/conf/:/conf/
- ./scripts/certificates/ssl/:/certs/
networks:
- bnkrl.io
labels:
- "traefik.enable=true"
- "traefik.http.routers.api.rule=Host(`traefik.bnkrl.io`)"
- "traefik.docker.network=bnkrl.io"
bankroll:
container_name: bankroll
build:
context: .
ports:
- "3000"
volumes:
- .:/usr/src/app
command: yarn start
networks:
- bnkrl.io
labels:
- "traefik.http.routers.bankroll.rule=Host(`bankroll.bnkrl.io`)"
- "traefik.docker.network=bnkrl.io"
- "traefik.http.services.bankroll.loadbalancer.server.port=3000"
- "traefik.http.routers.bankroll-https.rule=Host(`bankroll.bnkrl.io`)"
- "traefik.http.routers.bankroll-https.tls=true"
networks:
bnkrl.io:
external: true
But for some reason the following is happening:
Running curl when ssh'd into my bankroll container gives the following:
/usr/src/app# curl bankroll.bnkrl.io
curl: (7) Failed to connect to bankroll.bnkrl.io port 80: Connection refused
Despite having - "traefik.http.services.bankroll.loadbalancer.server.port=3000" label set up.
I am also unable to hit traefik from my application container:
curl traefik.bnkrl.io
curl: (6) Could not resolve host: traefik.bnkrl.io
Despite my expectation to be able to do so since they are both on the same network.
Any help with understanding what I might be doing wrong would be greatly appreciated! My application (bankroll) is a very basic hello-world react app, but I don't think any of the details around that are relevant to the issue I'm facing.
EDIT: I am also not seeing any error logs on traefik side of things.
You are using host names that are not declared and therefore are unreachable.
To reach a container from another container, you need to use the service name, for example, if you connect to bankroll from the reverse-proxy it will hit the other service.
While if you want to access them from the host machine, you will have to publish the ports (which you did, it's all the stuff in ports in your Docker-compose file) and access from localhost or from your machine local IP address instead of traefik.bnkrl.io.
If you want to access from traefik.bnkrl.io, you will have to declare this host name, and point it to the place where the Docker containers are running from.
So either a DNS record in the domain bnkrl.io pointing to your local machine, or a HOSTS file entry in your computer pointing to 127.0.0.1.
Another note: For SSL you are going to need a valid certificate to use for the host name. While in local development, you can use the self-signed certificate provided by Traefik, but you may have to install it in the computer connecting to the service, or allow untrusted certificates from your browser, or wherever you are making the requests from (some browsers no longer support using self-signed certificates). For SSL on the Internet you will need to look at things like Let's Encrypt.

Access a container from another

I see other posts but don't work in my case, maybe i'm beeing dumb.
I tried everything.
My last version of Dockerfile:
version: '3.4'
services:
bookmemoriesfrontend:
image: ${DOCKER_REGISTRY-}bookmemoriesfrontend
build:
context: .
dockerfile: Frontend\BookMemoriesFrontend\Dockerfile
ports:
- "8000:443"
depends_on:
- booksapi
- authorsapi
authorsapi:
image: ${DOCKER_REGISTRY-}authorsapi
build:
context: .
dockerfile: Services\AuthorsAPI\Dockerfile
ports:
- "8002:443"
booksapi:
image: ${DOCKER_REGISTRY-}booksapi
build:
context: .
dockerfile: Services\BooksAPI\Dockerfile
ports:
- "8001:443"
When I open CLI from BookMemoriesFrontend, I tried several curl commmand, when i try :
curl Booksapi/api/book
I think it will receive the api result and I dont receive nothing in result.
When I run CLI my machine:
curl -s https://localhost:8001/api/book
It gives the API result.
Please help me, I'm around this almost a week.
You should be able to use curl https://booksapi/api/book or curl https://booksapi:443/api/book.
Since it's https, it'll make the request on port 443 by default, which is what the container is listening on, so there's no need to specify a port.
Port 8001 is only used when you access the API from the host machine. When you're on the bridge network that docker-compose creates, you use the container ports directly.

Vuejs nginx dockerised app not working with docker-compose

I have a production stage dockerised vuejs front end app served with nginx server.
When I run the single container using the command:
docker run -p 80:80 my-dockerhub-username/my-vuejs-app
then it runc fine and I can reach it on port 80.
...however, for some reason when I use docker-compose to spin up my app using the following docker-compose.yml:
version: '3'
services:
api:
image: my-dockerhub-username/my-vuejs-app
ports:
- 80:80
web:
image: my-dockerhub-username/my-rest-api
ports:
- 9001:9001
I cannot reach my app on port 80.
Has anybody else experienced this issue?
I would appreciate any sugestions anybody can offer. Thanks in advance.

docker-compose resolve hostname in url

Tried looking around but couldn't find anything close to what I need.
I have a docker-compose file with a docker container (web) that uses another container's IP (api) in its environment variable by resolving the hostname:
version: '3'
services:
web:
build: ../client/
ports:
- "5000:5000"
- "3000:3000"
environment:
REACT_APP_API_DEV: http://api:8000/server/graphql
api:
build: ../server/
env_file:
- server_variables.env
ports:
- "8000:8000"
redis:
image: "redis:alpine"
My issue is that web doesn't resolve this variable when it's running. I can ping api just fine inside the web container but http://api:8000 doesn't resolve properly. I also tried making HOST=api the variable and building the URI manually but that doesn't work either.
EDIT: I added a complete docker-compose.yml file for reference. I can curl the api just fine from inside the web container, but my app can't seem to resolve it properly. I'm using NodeJS and React
Alright, I found the issue. Apparently, my web container was fetching from api with the http://api:8000 URI but my browser doesn't know what api is (only the containers do).
I followed the stuff suggested in here to resolve the hostname on my machine and it worked out.
You have to link them using network
version: '3'
services:
web:
...
environment:
- HOST: http://api:8000
networks:
- my-network
...
api:
networks:
- my-network
...
networks:
my-network:

Docker-compose doesn't resolve DNS to correct service

I have two services, web and helloworld. The following is my docker-compose YAML file:
version: "3"
services:
helloworld:
build: ./hello
volumes:
- ./hello:/usr/src/app
ports:
- 5001:80
web:
build: ./web
volumes:
- ./web:/usr/share/nginx/html
ports:
- 5000:80
depends_on:
- helloworld
Inside the index.html in web, I made a button that opens http://helloworld when clicked on. However, my button ends up going to helloworld.com instead of the correct service. Both services work fine when I do localhost:5001 and localhost:5000. Am I missing something?
Docker's embedded DNS for service discovery is for container-to-container networking. For connections from outside of docker (e.g. from your browser) you need to publish the port (e.g. 5000 and 5001 in your file) and connect to that published port.
To use the container-to-container networking, you would need the DNS lookup to happen inside of the web container and the connection to go from web to helloworld, instead of from your browser to the container.
Edit: from your comment, you may find a reverse proxy helpful. Traefik and nginx-proxy are two examples out there. You can configure these to forward to containers by hostname or by a virtual path, and in your situation, I think path based routing would be easier. The resulting compose file would look something like:
version: "3"
services:
traefik:
image: traefik
command: --docker --docker.watch
volumes:
- /var/lib/docker.sock:/var/lib/docker.sock
ports:
- 8080:80
helloworld:
build: ./hello
volumes:
- ./hello:/usr/src/app
labels:
- traefik.frontend.rule=PathPrefixStrip:/helloworld
- traefik.port=80
web:
build: ./web
volumes:
- ./web:/usr/share/nginx/html
labels:
- traefik.frontend.rule=PathPrefixStrip:/
- traefik.port=80
The above is all untested off the top of my head configuration, but should get you in the right direction. With the PathPrefixStrip rule, you can make a link in web to "/helloworld" which will go to the other container. And since the link doesn't have a hostname or port, it will go to the same traefik hostname/port you are already using.

Resources