Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker ip is not generated in the /etc/nginx/conf.d/default.conf file #380

Closed
odedpriva opened this issue Mar 3, 2016 · 6 comments
Closed

Comments

@odedpriva
Copy link

I started the proxy container using the following command
docker run -d -p 80:80 --net=node_default --name proxy -v /var/run/docker.sock:/tmp/docker.sock -t jwilder/nginx-proxy

I started a simple node container

FROM node:4.2
WORKDIR /srv
ADD ./package.json /srv/package.json
RUN npm install
ADD . /srv
EXPOSE 3000
CMD node app.js

my docker-compose file

version: "2"

services:
  worker:
    image: docker-node-meetup9
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "3000:3000"
    command: node app.js
    hostname: docker-node-meetup9
    environment:
      - VIRTUAL_HOST=myapp1.dev

here is what was generated in the /etc/nginx/conf.d/default.conf file
upstream myapp1.dev { # node_worker_1 server :3000; } server { server_name myapp1.dev; listen 80 ; access_log /var/log/nginx/access.log vhost; location / { proxy_pass http://myapp1.dev; } }

the container ip is missing.

any idea why?

➜  node git:(master) ✗ docker version
Client:
 Version:      1.10.1
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   9e83765
 Built:        Fri Feb 12 22:11:40 UTC 2016
 OS/Arch:      darwin/amd64

Server:
 Version:      1.10.2
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   c3959b1
 Built:        Mon Feb 22 22:37:33 2016
 OS/Arch:      linux/amd64
➜  node git:(master) ✗ docker-compose version
docker-compose version 1.6.0, build unknown
docker-py version: 1.7.0
CPython version: 2.7.10
OpenSSL version: OpenSSL 0.9.8zg 14 July 2015
@pitkley
Copy link
Contributor

pitkley commented Mar 8, 2016

nginx-proxy doesn't support overlay-networks yet (which are used by docker-compose v1.6.0), there is the ongoing PR #337 which tries to solve this issue.

For the time being, you will have to use docker-compose with version-spec 1.

@odedpriva
Copy link
Author

But shouldn't it work if both proxy and containers are running in the same network ?

Sent from my iPhone

On 8 במרץ 2016, at 11:00, Pit notifications@github.com wrote:

nginx-proxy doesn't support overlay-networks yet (which are used by docker-compose v1.6.0), there is the ongoing PR #337 which tries to solve this issue.

For the time being, you will have to use docker-compose with version-spec 1.


Reply to this email directly or view it on GitHub.

@pitkley
Copy link
Contributor

pitkley commented Mar 8, 2016

Unfortunately not. #337 has to be merged for user-defined networks to work.

@odedpriva
Copy link
Author

I'm getting the same result when not using overlay like so
starting the nginx container
docker run -d -p 80:80 --name=nginxg-rproxy --net=bridge -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy

starting a jenkins container
docker run -d -p 8080:8080 -p 50000:50000 --net=bridge --name jenkins -e VIRTUAL_HOST=jenkins.dev -v plugins:/var/jenkins_home/plugins jenkins

docker exec nginxg-rproxy cat /etc/nginx/conf.d/default.conf

>> docker logs nginxg-rproxy
forego     | starting nginx.1 on port 5000
forego     | starting dockergen.1 on port 5100
dockergen.1 | 2016/03/14 06:52:43 Generated '/etc/nginx/conf.d/default.conf' from 2 containers
dockergen.1 | 2016/03/14 06:52:44 Watching docker events
dockergen.1 | 2016/03/14 06:52:55 Received event die for container 12cbaf338a79
dockergen.1 | 2016/03/14 06:52:56 Generated '/etc/nginx/conf.d/default.conf' from 1 containers
dockergen.1 | 2016/03/14 06:52:56 Running 'nginx -s reload'
dockergen.1 | 2016/03/14 06:57:04 Received event start for container d3c08ae53245
dockergen.1 | 2016/03/14 06:57:04 Generated '/etc/nginx/conf.d/default.conf' from 2 containers
dockergen.1 | 2016/03/14 06:57:04 Running 'nginx -s reload'
docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                              NAMES
d3c08ae53245        jenkins               "/bin/tini -- /usr/lo"   12 minutes ago      Up 12 minutes       0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   jenkins
52d727789549        jwilder/nginx-proxy   "/app/docker-entrypoi"   16 minutes ago      Up 16 minutes       0.0.0.0:80->80/tcp, 443/tcp                        nginxg-rproxy
>> docker exec  nginxg-rproxy cat /etc/nginx/conf.d/default.conf
upstream jenkins.dev {
        # jenkins
        server 172.17.0.3 down;
}
server {
    server_name jenkins.dev;
    listen 80 ;
    access_log /var/log/nginx/access.log vhost;
    location / {
        proxy_pass http://jenkins.dev;
    }
}

Any idea why?

@pitkley
Copy link
Contributor

pitkley commented Mar 14, 2016

This:

upstream jenkins.dev {
        # jenkins
        server 172.17.0.3 down;
}

is not the same result as this:

upstream myapp1.dev {
        # node_worker_1
        server :3000;
}

Your issue now is that you have published ports 8080 and 50000 on your Jenkins container, and nginx-proxy doesn't know which one to use. You need to specifiy this in the environment variable VIRTUAL_PORT:

docker run -d -p 8080:8080 -p 50000:50000 --net=brdige --name jenkins -e VIRTUAL_HOST=jenkins.dev -e VIRTUAL_PORT=8080 -v plugins:/var/jenkins_home/plugins jenkins

See Multiple Ports for more information.

@tkw1536
Copy link
Collaborator

tkw1536 commented Apr 10, 2022

Resolved by previous comment, closing.

@tkw1536 tkw1536 closed this as completed Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants