最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to Set Port Mapping Directly in docker-compose.yml? - Stack Overflow

programmeradmin0浏览0评论

I am trying to install NetBox using Docker Compose following the official repository: NetBox Docker.

The quickstart guide suggests adding a docker-compose.override.yml with the following configuration:

The quickstart guide suggests adding a docker-compose.override.yml with the following configuration:

services:
  netbox:
    ports:
      - "8000:8080"

I followed this method, and it works fine.

However, I want to define the port mapping directly in docker-compose.yml instead of using an override file. I attempted to add the ports section under servicesbox in docker-compose.yml, but it is not working.

Here’s the relevant part of my docker-compose.yml:

services:
  netbox: &netbox
    image: docker.io/netboxcommunity/netbox:${VERSION-v4.2-3.1.1}
    depends_on:
      - postgres
      - redis
      - redis-cache
    env_file: env/netbox.env
    user: "unit:root"
    healthcheck:
      test: curl -f http://localhost:8080/login/ || exit 1
      start_period: 90s
      timeout: 3s
      interval: 15s
    ports:
      - 8000:8080
    volumes:
      - ./configuration:/etc/netbox/config:z,ro
      - netbox-media-files:/opt/netbox/netbox/media:rw
      - netbox-reports-files:/opt/netbox/netbox/reports:rw
      - netbox-scripts-files:/opt/netbox/netbox/scripts:rw

After running docker-compose up, the NetBox container starts, but I am unable to access it via http://localhost:8000. It seems like the port mapping is not applied.

Questions: Is there a specific reason why port mapping works in docker-compose.override.yml but not in docker-compose.yml? Am I missing any required configuration in docker-compose.yml to make this work? Any help would be appreciated!

发布评论

评论列表(0)

  1. 暂无评论