使用Docker Compose将DDEV Web容器端口公开给主机 [英] Using Docker Compose to expose DDEV web container ports to host machine

查看:74
本文介绍了使用Docker Compose将DDEV Web容器端口公开给主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经配置了一个DDEV Drupal环境,在该环境中,我需要针对我的主题运行Pattern Lab.我的学生将使用此环境,他们可能不熟悉在本地计算机上安装Node或Node依赖项工具的情况(Pattern Lab需要Node).解决方法是,我将Pattern Lab设置为在DDEV的Web容器中运行.我遇到的问题是,由于Pattern Lab在DDEV容器中运行,因此无法在主机上访问它.有没有人做过类似的事情来将Docker端口暴露给主机?

I have configured a DDEV Drupal environment in which I need to run Pattern Lab for my theme. This environment will be used by students of mine who may not be well-versed in installing Node or Node dependencies tools on their local computers (Pattern Lab requires Node). As a workaround, I am setting Pattern Lab to run in the DDEV's web container. The problem I am having is that since Pattern Lab is running in a DDEV container, I can't access it on my host computer. Has anyone done something similar to expose Docker ports to the host machine?

推荐答案

在后台,DDEV使用docker-compose定义并运行构成项目本地环境的多个容器.docker-compose支持定义多个撰写文件,以促进在文件和项目之间共享撰写配置,而DDEV旨在利用此功能.这是我为解决此问题而采取的步骤:

Under the hood, DDEV uses docker-compose to define and run the multiple containers that make up the local environment for a project. docker-compose supports defining multiple compose files to facilitate sharing Compose configurations between files and projects, and DDEV is designed to leverage this ability. Here are the steps I took to solve this issue:

  • .ddev/内部,我创建了一个名为 docker-compose.patternlab.yaml 的文件.文件名的第二部分( patternlab )可以是您想要的任何内容.使用与您要实施的操作,应用或服务相关的名称是很有意义的.
  • 我添加了以下代码,以将Web容器的端口3000暴露给主机的端口3000(https)和3001(http):
  • Inside .ddev/ I created a file called docker-compose.patternlab.yaml. The second part of the file name (patternlab), can be anything you want. It makes sense to use a name that is related to the action, app, or service you are trying to implement.
  • I added the code below to expose the web container's port 3000 to the host's port 3000 (https), and 3001(http):
# Override the web container's standard HTTP_EXPOSE and HTTPS_EXPOSE services
# to expose port 3000 of DDEV's web container.
version: '3.6'
services:
  web:
    # ports are a list of exposed *container* ports
    ports:
      - "3000"
    environment:
      - HTTP_EXPOSE=${DDEV_ROUTER_HTTP_PORT}:80,${DDEV_MAILHOG_PORT}:8025,3001:3000
      - HTTPS_EXPOSE=${DDEV_ROUTER_HTTPS_PORT}:80,${DDEV_MAILHOG_HTTPS_PORT}:8025,3000:3000

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆