首页 > 其他分享 >Use Compose Watch

Use Compose Watch

时间:2025-01-11 18:10:45浏览次数:7  
标签:Use Compose http -- traefik app Watch services backend

Use Compose Watch

https://docs.docker.com/compose/how-tos/file-watch/#:~:text=Run%20docker%20compose%20up%20--watch%20to%20build%20and,source%20files%20using%20your%20preferred%20IDE%20or%20editor.

The watch attribute automatically updates and previews your running Compose services as you edit and save your code. For many projects, this enables a hands-off development workflow once Compose is running, as services automatically update themselves when you save your work.

watch adheres to the following file path rules:

  • All paths are relative to the project directory
  • Directories are watched recursively
  • Glob patterns aren't supported
  • Rules from .dockerignore apply
    • Use ignore option to define additional paths to be ignored (same syntax)
    • Temporary/backup files for common IDEs (Vim, Emacs, JetBrains, & more) are ignored automatically
    • .git directories are ignored automatically

You don't need to switch on watch for all services in a Compose project. In some instances, only part of the project, for example the Javascript frontend, might be suitable for automatic updates.

Compose Watch is designed to work with services built from local source code using the build attribute. It doesn't track changes for services that rely on pre-built images specified by the image attribute.

 

作为APP镜像,应该将程序可运行文件打包进入docker镜像, 除了配置部分,这样便于应用部署。

# Run as a non-privileged user
FROM node:18
RUN useradd -ms /bin/sh -u 1001 app
USER app

# Install dependencies
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install

# Copy source files into application directory
COPY --chown=app:app . /app

 

但是对于开发环境, 需要将本地代码及时更新到容器内, compose watch提供开发环境支持。

 

例如此例子fastapi官方项目模板:

https://github.com/fastapi/full-stack-fastapi-template/blob/master/docker-compose.override.yml

services:

  # Local services are available on their ports, but also available on:
  # http://api.localhost.tiangolo.com: backend
  # http://dashboard.localhost.tiangolo.com: frontend
  # etc. To enable it, update .env, set:
  # DOMAIN=localhost.tiangolo.com
  proxy:
    image: traefik:3.0
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "80:80"
      - "8090:8080"
    # Duplicate the command from docker-compose.yml to add --api.insecure=true
    command:
      # Enable Docker in Traefik, so that it reads labels from Docker services
      - --providers.docker
      # Add a constraint to only use services with the label for this stack
      - --providers.docker.constraints=Label(`traefik.constraint-label`, `traefik-public`)
      # Do not expose all Docker services, only the ones explicitly exposed
      - --providers.docker.exposedbydefault=false
      # Create an entrypoint "http" listening on port 80
      - --entrypoints.http.address=:80
      # Create an entrypoint "https" listening on port 443
      - --entrypoints.https.address=:443
      # Enable the access log, with HTTP requests
      - --accesslog
      # Enable the Traefik log, for configurations and errors
      - --log
      # Enable debug logging for local development
      - --log.level=DEBUG
      # Enable the Dashboard and API
      - --api
      # Enable the Dashboard and API in insecure mode for local development
      - --api.insecure=true
    labels:
      # Enable Traefik for this service, to make it available in the public network
      - traefik.enable=true
      - traefik.constraint-label=traefik-public
      # Dummy https-redirect middleware that doesn't really redirect, only to
      # allow running it locally
      - traefik.http.middlewares.https-redirect.contenttype.autodetect=false
    networks:
      - traefik-public
      - default

  db:
    restart: "no"
    ports:
      - "5432:5432"

  adminer:
    restart: "no"
    ports:
      - "8080:8080"

  backend:
    restart: "no"
    ports:
      - "8000:8000"
    build:
      context: ./backend
    # command: sleep infinity  # Infinite loop to keep container alive doing nothing
    command:
      - fastapi
      - run
      - --reload
      - "app/main.py"
    develop:
      watch:
        - path: ./backend
          action: sync
          target: /app
          ignore:
            - ./backend/.venv
            - .venv
        - path: ./backend/pyproject.toml
          action: rebuild
    # TODO: remove once coverage is done locally
    volumes:
      - ./backend/htmlcov:/app/htmlcov
    environment:
      SMTP_HOST: "mailcatcher"
      SMTP_PORT: "1025"
      SMTP_TLS: "false"
      EMAILS_FROM_EMAIL: "noreply@example.com"

  mailcatcher:
    image: schickling/mailcatcher
    ports:
      - "1080:1080"
      - "1025:1025"

  frontend:
    restart: "no"
    ports:
      - "5173:80"
    build:
      context: ./frontend
      args:
        - VITE_API_URL=http://localhost:8000
        - NODE_ENV=development

  playwright:
    build:
      context: ./frontend
      dockerfile: Dockerfile.playwright
      args:
        - VITE_API_URL=http://backend:8000
        - NODE_ENV=production
    ipc: host
    depends_on:
      - backend
      - mailcatcher
    env_file:
      - .env
    environment:
      - VITE_API_URL=http://backend:8000
      - MAILCATCHER_HOST=http://mailcatcher:1080
      # For the reports when run locally
      - PLAYWRIGHT_HTML_HOST=0.0.0.0
      - CI=${CI}
    volumes:
      - ./frontend/blob-report:/app/blob-report
      - ./frontend/test-results:/app/test-results
    ports:
      - 9323:9323

networks:
  traefik-public:
    # For local dev, don't expect an external Traefik network
    external: false

 

标签:Use,Compose,http,--,traefik,app,Watch,services,backend
From: https://www.cnblogs.com/lightsong/p/18666068

相关文章

  • Avalonia UserControl Grid布局
    <!--定义列--><Grid.ColumnDefinitions><ColumnDefinitionWidth="*"/></Grid.ColumnDefinitions><!--按钮区域--><StackPanelOrientation="Horizontal"Grid.Row="0"><TextBlockPadding......
  • langfuse从v2升级到v3(异机升级)
    环境:OS:Centos7说明:v3部署在新机器,我们需要将v2下的postgresql外挂的数据目录文件拷贝到v3下的外挂数据目录1.停掉v2版本停掉v2的目的是postgresql没有事务写入,可以直接拷贝数据目录到v3版本使用[root@localhostlangfuse]#pwd/home/middle/langfuse/langfuse[root@localho......
  • Docker Compose 模板文件详解与实践示例
    DockerCompose是一种用于定义和运行多容器Docker应用程序的工具。其核心是docker-compose.yml模板文件,该文件以YAML格式编写,包含了定义服务、网络和卷等所需的指令。本文将详细介绍DockerCompose模板文件中的关键指令,并通过示例代码和运行结果帮助大家更好地理解......
  • Gbase8a suse环境安装遇到的rpms缺失问题
    一、suse环境下安装依赖包工具zypper在suse环境下安装gbase8a集群,有时会遇到这样的报错信息“Error:gcinstall.py(line2520)–clusterneedssomerpmstorunning"示例:./gcinstall.py–silent=demo.options…EnvironmentalCheckingongclusternodes.Error:gcinsta......
  • Vue3 watch监视 reactive
    一、引入import{reactive,watch}from'vue'二、注意1、监视reactive定义的响应式对象时,oldval无法正确获取,强制开启深度监视,无法关闭2、监视reactive对象的某个属性时,deep有效(属性为对象),属性为字符串或数字oldvalue可以正常获取三、四种情况1、情况一监听reactive......
  • langfuse从v2升级到v3(本地升级)
    环境:OS:Centos7#################################################部署v2###########################################################1.部署v2v2资源清单配置文件如下:[root@host135langfuse]#moredocker-compose.ymlservices:langfuse-server:image:regi......
  • 关于redisson的一些问题,为什么要用watchDog
    redisson获取不到锁怎么处理1.阻塞等待锁释放:redisson有waitTimeout参数控制锁等待时间,当某线程获取不到锁时,会进入阻塞状态等待锁释放或超过设置的时间2.tryLock会根据参数直接返回或者抛出异常。 tryLock一般有两种:一种是不带参数的,这种不会阻塞,锁可用就返回true,锁不可用就......
  • langfuse v3(docker compose安装)安装部署
    环境:OS:Centos7langfuse:v31.下载dockercompose配置文件https://github.com/langfuse/langfuse/blob/v3.5.3/docker-compose.yml[root@host135home]#mkdir-p/home/middle/langfuse/langfuse上传配置文件到该目录[root@host135langfuse]#lsdocker-compose.yml[root@host......
  • ERROR: syntax error at or near "user" LINE 1: CREATE TABLE user (
    在PostgreSQL中,user是一个关键字,因为它用于定义数据库用户和权限,因此直接将表名命名为user会导致语法错误为避免这种情况,你可以选择一下几种方法之一: 1使用双引号将表名括起来以便让PostgreSQL识别它是一个标识符而不是一个关键字 请注意,使用双引号后,表名......
  • windows下php安装依赖版本工具composer
    1.先把php加入到环境变量 2.直接下载composer.phar,地址:https://dl.laravel-china.org/composer.phar把下载的composer.phar放到PHP安装目录  命令下载: php-r"copy('https://getcomposer.org/installer','composer-setup.php');"phpcomposer-setup.phpphp......