docker-ngrok icon indicating copy to clipboard operation
docker-ngrok copied to clipboard

Issue when docker-compose

Open lorddaren opened this issue 8 years ago • 11 comments

When using docker compose I have to set the HTTP_PORT as an environment variable and it will not map to the linked host.

 nginx-proxy:
    container_name: nginx-proxy
    image: nginx
    ports:
      - "0.0.0.0:80:80"
      - "0.0.0.0:443:443"
    volumes:
      - "./volumes/conf.d:/etc/nginx/conf.d"
      - "./volumes/vhost.d:/etc/nginx/vhost.d"
      - "./volumes/certs:/etc/nginx/certs:ro"
      - "/usr/share/nginx/html"
 ngrok:
    container_name: ngrok
    ports:
      - "0.0.0.0:4040:4040"
    image: wernight/ngrok
    links:
      - nginx-proxy
    environment:
      - NGROK_AUTH=<auth key>
      - NGROK_SUBDOMAIN=mysubdomain

Am I missing something? If I add the HTTP_PORT things get connected but ngrok complains it can't forward to localhost:80

lorddaren avatar May 10 '16 18:05 lorddaren

There is no HTTP_PORT env variable support. Where did you see that? See https://github.com/wernight/docker-ngrok

wernight avatar May 11 '16 10:05 wernight

If I don't set it then the ngrok command does not execute appropriately.

In looking at the entrypoint.sh script I believe it is this portion that is hanging me up:

lorddaren avatar May 11 '16 19:05 lorddaren

If I don't set it then the ngrok command does not execute appropriately.

In looking at the entrypoint.sh script I believe it is this portion that is hanging me up:

if [ -n "$HTTPS_PORT" ]; then
  FWD="`echo $HTTPS_PORT | sed 's|^tcp://||'`"
elif [ -n "$HTTP_PORT" ]; then
  FWD="`echo $HTTP_PORT | sed 's|^tcp://||'`"
elif [ -n "$APP_PORT" ]; then
  FWD="`echo $APP_PORT | sed 's|^tcp://||'`"
fi

Maybe it is because I am using the newer 1.7 docker-compose and 1.11 docker?

lorddaren avatar May 11 '16 19:05 lorddaren

I forgot why this is there but it works without, just following the README.

Can also use host:

$ docker run --rm -it --net=host wernight/ngrok ngrok http localhost:80

wernight avatar May 11 '16 20:05 wernight

Added NGROK_PORT, you may also use the command-line directly. Let me know if it helps.

wernight avatar Jul 08 '16 07:07 wernight

This was tripping me out for a while, until I realized that "NGROK_PORT" can also have a container alias. So I made it work with:

  nginx:
    depends_on:
      - phpfpm
    ports:
      - "80:80"
      - "443:443"
    image: nginx:latest
    volumes:
      - "./wordpress:/var/www/html"
      - "./config/nginx/default.conf:/etc/nginx/conf.d/default.conf"
      - "./config/certs:/etc/nginx/certs"
      - "./logs/nginx:/var/log/nginx"
    restart: always
  ngrok:
    container_name: ngrok
    ports:
      - "0.0.0.0:4040:4040"
    image: wernight/ngrok
    links:
      - "nginx"
    environment:
      - NGROK_AUTH=<>
      - NGROK_SUBDOMAIN=<>
      - NGROK_REGION=eu
      - NGROK_PORT=nginx:80

artpi avatar Feb 08 '18 09:02 artpi

@artpi saved my day.

ghost avatar Jul 24 '18 08:07 ghost

Great job, so tiny image! But please add this - NGROK_PORT=nginx:80 to the readme, I've spent some time searching why environment variables does not working (ended up by looking source and entrypoint.sh, then issues)

andrius avatar Dec 17 '18 20:12 andrius

Would you like to suggest a pull-request for the README change? As a user, you're in the best place to know how it could be worded.

wernight avatar Jan 04 '19 12:01 wernight

Using docker compose would also work without environment variables when you put the container in the same network:

ngrok:
  container_name: ngrok
  image: wernight/ngrok
  command: ngrok http apache:8080
  networks:
    - apache
  ports:
    -  '4040:4040'

rvanlaak avatar Jul 18 '19 12:07 rvanlaak

Since "links" is legacy feature, I'd rather use "networks" especially since “links” doesn't work for me due to error "The error encountered was: dial tcp: lookup nginx on 127.0.0.11:53: no such host"

This way works for me:

nginx:
    image: nginx:alpine
    container_name: nginx
    restart: unless-stopped
    tty: true
    environment:
      SERVICE_NAME: nginx
    ports:
      - 3000:80
    volumes:
      - ./src:/app
      - ./docker/nginx/conf.d/:/etc/nginx/conf.d/
    networks:
      - app-network
ngrok:
    container_name: ngrok
    ports:
      - "0.0.0.0:4040:4040"
    image: wernight/ngrok
    environment:
      - NGROK_AUTH=<>
      - NGROK_SUBDOMAIN=<>
      - NGROK_REGION=eu
      - NGROK_PORT=nginx:80
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

magentinos avatar Mar 25 '20 20:03 magentinos