变更未反映在Docker上

im9ewurl  于 2023-02-11  发布在  Docker
关注(0)|答案(1)|浏览(135)

我是docker的新手,我用的是windows11,当我尝试修改代码时,我发现代码的修改并没有反映在docker上,除非我删除所有的容器和图像,然后重新构建,然后只反映。这太麻烦和耗时了,有没有其他方法可以让它自动观察修改并自动反映?
这是我的docker-compose. yml

version: "3.3"

services:
  db:
    image: mysql:5.7
    restart: always
    command: --max_allowed_packet=32505856
    volumes:
      - db_volume:/var/lib/mysql
    ports:
      - "9002:3306"
    environment:
      MYSQL_ROOT_PASSWORD: pw
      MYSQL_DATABASE: dbname
      MYSQL_USER: dbuser
      MYSQL_PASSWORD: dbpassword
    networks:
      - internal
  web:
    depends_on:
      - db
    image: web:1.0.1
    build: .
    ports:
      - "9001:80"
    restart: always
    environment:
      MYSQL_HOST: db
      MYSQL_PORT: 3306
      MYSQL_USER: user
      MYSQL_PASSWORD: pw
      MYSQL_DATABASE: db
    networks:
      - internal
    volumes:
      - drupal-data:/var/www/html
  phpmyadmin:
    image: phpmyadmin
    restart: always
    depends_on:
      - db
    ports:
      - 9004:80
    environment:
      PMA_HOST: db
      PMA_USER: user
      PMA_PASSWORD: pw
      UPLOAD_LIMIT: 4000M
    networks:
      - internal
volumes:
  db_volume:
  drupal-data:
networks:
  internal:
    driver: bridge

这是我的Dockerfile

FROM drupal:9.2.5-php7.4-apache

RUN docker-php-ext-install mysqli

COPY ./k8s/php.ini "$PHP_INI_DIR/php.ini"

COPY ./k8s/000-default.conf /etc/apache2/sites-available/

COPY --chown=www-data:www-data . /var/www/html

WORKDIR /var/www/html

RUN composer install

# Install php-redis - this is for drupal redis module
# RUN pecl install -o redis && \
#   echo "extension=redis.so" > /usr/local/etc/php/conf.d/redis.ini
  
# # Installing modules
# RUN composer require 'acquia/lightning:~5.2.0'
# RUN composer require 'cweagans/composer-patches:^1.6.0'
# RUN composer require 'oomphinc/composer-installers-extender:^1.1 || ^2'
# RUN composer require 'drupal/advagg:^4.1'
# RUN composer require 'drupal/autosave_form:^1.2'
# RUN composer require 'drupal/backup_migrate:^5.0'
# RUN composer require 'drupal/conditional_fields:^4.0@alpha'
# RUN composer require 'drupal/entity_reference_revisions:^1.9'
# RUN composer require 'drupal/field_group:^3.1'
# RUN composer require 'drupal/http_client_manager:^2.5'
# RUN composer require 'drupal/moderated_content_bulk_publish:^2.0'
# RUN composer require 'drupal/pathauto:^1.8'
# RUN composer require 'drupal/quick_node_clone:^1.14'
# RUN composer require 'drupal/svg_image:^1.14'
# RUN composer require 'drupal/svg_image_field:^2.0'

# # Installing other dependencies
# RUN composer require 'phpoffice/phpspreadsheet:1.18'
# RUN composer require 'lodash-php/lodash-php:^0.0.7'

# RUN composer require drush/drush 10.6 && ln -s $(pwd)/vendor/bin/drush /usr/local/bin/drush

RUN ln -s /var/www/html/docroot /var/www/html/docroot/tv

COPY ./k8s/php.min.ini "$PHP_INI_DIR/conf.d/php.ini"

# RUN rm "$PHP_INI_DIR/php.ini"

RUN chmod 777 -R /var/www/html/docroot/sites/default/files

RUN apache2ctl restart

EXPOSE 80

我正在使用docker compose up -d启动网站
我做错了什么?

ss2ws0br

ss2ws0br1#

我觉得你需要...
为此,您需要在volumes in web中添加以下代码行:

volumes:
    - ./:/var/www/html  # This maps the local code directory to the container directory
    - drupal-data:/var/www/html

借助此功能,无需重新构建映像即可在容器内部反映所做的更改

相关问题