Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Adding Local Addresses in Nginx Proxy Manager Using Docker Container Domains in Docker Compose

Tiempo de lectura: 2 minutos

Reading time: 2 minutes

When implementing Nginx Proxy Manager in Docker or Docker Compose, it is important to ensure that it accesses the implemented containers/services using a local address to avoid going through the public network if the connection is not SSL internally. This way, we prevent unencrypted traffic from going outside.

The first thing we need to do is to connect the Docker containers in the Docker Compose file by adding links:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
version: "3.1"
services:
miservicio_mysql:
image: biarms/mysql:5.7
env_file:
- ./Dockerfile/mysql.env
container_name: mysql_container
command: --max_allowed_packet=67108864
environment:
MYSQL_DATABASE: "db"
MYSQL_USER: "user"
MYSQL_PASSWORD: "pass_user"
# Password for root access
MYSQL_ROOT_PASSWORD: "pass_root"
volumes:
# Mount a volume for MySQL to preserve database data
- ./mysql:/var/lib/mysql
expose:
- 3306
ports:
- 3306:3306
networks:
- docker-network
miservicio_php:
build:
context: ./Dockerfile
dockerfile: php_file
env_file:
- ./Dockerfile/php.env
container_name: php_container
volumes:
- ./www/:/var/www/html
- ./logs/apache:/var/log/apache2
expose:
- 80
- 443
ports:
- 8000:80
- 442:443
links:
- miservicio_mysql
networks:
- docker-network
adminer:
image: adminer
restart: always
ports:
- 8080:8080
links:
- miservicio_mysql:db
networks:
- docker-network
nginxproxymanager:
image: 'jc21/nginx-proxy-manager:latest'
restart: unless-stopped
ports:
# These ports are in the format :
- '80:80' # Public HTTP Port
- '443:443' # Public HTTPS Port
- '81:81' # Admin Web Port
# Default user:
# Email: admin@example.com
# Password: changeme
volumes:
- ./config/proxymanager/data:/data
- ./config/letsencrypt:/etc/letsencrypt
networks:
- docker-network
links:
- miservicio_mysql
- miservicio_php
- adminer
networks:
docker-network:
driver: bridge
version: "3.1" services: miservicio_mysql: image: biarms/mysql:5.7 env_file: - ./Dockerfile/mysql.env container_name: mysql_container command: --max_allowed_packet=67108864 environment: MYSQL_DATABASE: "db" MYSQL_USER: "user" MYSQL_PASSWORD: "pass_user" # Password for root access MYSQL_ROOT_PASSWORD: "pass_root" volumes: # Mount a volume for MySQL to preserve database data - ./mysql:/var/lib/mysql expose: - 3306 ports: - 3306:3306 networks: - docker-network miservicio_php: build: context: ./Dockerfile dockerfile: php_file env_file: - ./Dockerfile/php.env container_name: php_container volumes: - ./www/:/var/www/html - ./logs/apache:/var/log/apache2 expose: - 80 - 443 ports: - 8000:80 - 442:443 links: - miservicio_mysql networks: - docker-network adminer: image: adminer restart: always ports: - 8080:8080 links: - miservicio_mysql:db networks: - docker-network nginxproxymanager: image: 'jc21/nginx-proxy-manager:latest' restart: unless-stopped ports: # These ports are in the format : - '80:80' # Public HTTP Port - '443:443' # Public HTTPS Port - '81:81' # Admin Web Port # Default user: # Email: admin@example.com # Password: changeme volumes: - ./config/proxymanager/data:/data - ./config/letsencrypt:/etc/letsencrypt networks: - docker-network links: - miservicio_mysql - miservicio_php - adminer networks: docker-network: driver: bridge
version: "3.1"

services:
  miservicio_mysql:
    image: biarms/mysql:5.7
    env_file:
       - ./Dockerfile/mysql.env
    container_name: mysql_container
    command: --max_allowed_packet=67108864
    environment:
        MYSQL_DATABASE: "db"
        MYSQL_USER: "user"
        MYSQL_PASSWORD: "pass_user"
          # Password for root access
        MYSQL_ROOT_PASSWORD: "pass_root"
    volumes:
      # Mount a volume for MySQL to preserve database data
      - ./mysql:/var/lib/mysql
    expose:
      - 3306
    ports:
      - 3306:3306
    networks:
      - docker-network
  miservicio_php:
    build: 
      context: ./Dockerfile
      dockerfile: php_file
    env_file:
       - ./Dockerfile/php.env
    container_name: php_container
    volumes:
      - ./www/:/var/www/html
      - ./logs/apache:/var/log/apache2
    expose:
      - 80
      - 443
    ports:
      - 8000:80
      - 442:443
    links: 
      - miservicio_mysql
    networks:
      - docker-network
  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
    links: 
      - miservicio_mysql:db
    networks:
      - docker-network
  nginxproxymanager:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      # These ports are in the format :
      - '80:80' # Public HTTP Port
      - '443:443' # Public HTTPS Port
      - '81:81' # Admin Web Port
    # Default user:
    # Email: admin@example.com
    # Password: changeme

    volumes:
      - ./config/proxymanager/data:/data
      - ./config/letsencrypt:/etc/letsencrypt
    networks:
      - docker-network
    links: 
      - miservicio_mysql
      - miservicio_php
      - adminer

networks:
  docker-network:
    driver: bridge

As you can see in the example, I have added links in the nginxproxymanager container:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
- miservicio_mysql
- miservicio_php
- adminer
- miservicio_mysql - miservicio_php - adminer
 - miservicio_mysql
 - miservicio_php
 - adminer

This allows nginxproxymanager to access these containers locally.

Additionally, I have connected them through a Docker network named docker-network.

Now, in Nginx Proxy Manager, log in and go to the proxies:

Now, add or edit one and instead of using the IP, use the name of the container (either the one specified in the root or within the container_name tag):

And most importantly, remember to use the original service port in your Docker, not the exposed one. In other words, use the port on the right side within the ports section of your Docker Compose containers:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ports:
- 8000:80
- 442:443
ports: - 8000:80 - 442:443
 ports:
      - 8000:80
      - 442:443
0

Leave a Comment