Accessing docker container (webserver Nginx) from my Browser

Viewed 18

I am doing a project with docker, where I have to configure a web server onto a container and this to be reached from my web browser. Ive created my Test environment in VMware using debian. I configured a nginx reverse proxy and also a dockerfile for my web server. Below you will find my docker-compose.yml file.

services:
    reverse-proxy:
        image: "jwilder/nginx-proxy:alpine"
        container_name: "reverse-proxy"
        volumes:
            - "/usr/share/nginx/html"
            - "/etc/nginx/dhparam"
            - "/etc/nginx/vhost.d"
            - "/etc/nginx/certs"
            - "/run/docker.sock:/tmp/docker.sock:ro"
        restart: "always"
        ports:
            - "80:80"
            - "443:443"
    container:
        depends_on:
            - reverse-proxy
        image: web-new:latest
        container_name: "webserver"
        restart: unless-stopped

Now the container is all configured and when i try to access it with its ip (curl) it works and im trying to reach it from my Windows Host browser but its not working. Anyone can help, I am new on this docker journey and I would really appreciate some help.

Thank you.

1 Answers

A few suggestions:

  • share more: what version of compose are you using (I'm not seeing it in your provided example), what does your nginx config look like? without seeing the full picture it can be hard for folks here to help you triangulate your problem.

  • never name a docker service "container" as you did below

    container:  <---- HERE
        depends_on:
            - reverse-proxy
        image: web-new:latest
        container_name: "webserver"
        restart: unless-stopped

the keyword "container" is so often used with docker commands (e.g., docker container ls, you'll get confused / errors using this as your service name too (e.g., docker container logs container!!)

  • what do the logs of both containers look like? e.g., docker logs reverse-proxy? you'll likely find hints in one/both as to your problem.

  • I see you're using jwilder's excellent proxy image jwilder/nginx-proxy - have you been able to successfully run the example compose file from its dockerhub repo - repeated below for convenience? If not - start here (start simple, especially if you're new with docker, and push on complexity one layer at a time).

version: '2'

services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro

  whoami:
    image: jwilder/whoami
    environment:
      - VIRTUAL_HOST=whoami.local
Related