繁体   English   中英

Docker复制无效,内容未更新

[英]Docker copy not work, content not updated

我尝试用php(symfony app)配置docker。

当我第一次构建容器时,symfony骨架应用程序出现在容器中,但是其他任何构建方法都不会更改容器内的任何内容。

Dockefile

FROM nginx:latest
RUN rm ./etc/nginx/conf.d/default.conf
COPY ./nginx/site.conf /etc/nginx/conf.d/site.conf
COPY . /var/www/html

CMD ["nginx", "-g", "daemon off;"]

码头工人组成

version: '3'
services:
  simple-app-symfony:
    image: simple-app-symfony
    build: .
    ports: 
      - "8080:80"
    links:
      - php 
    volumes:
      - data:/var/www/html
  php:
    image: php:7.1-fpm
    volumes:
      - data:/var/www/html
volumes:
  data: 

nginx / site.conf

server {
    listen 80;
    listen [::]:80;
    server_name ~.;

    root /var/www/html/public;
    index index.php index.html index.htm;

    #location ~ \.php$ {
    #   try_files $uri =404;
    #   fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #   fastcgi_pass php:9000;
    #   fastcgi_index index.php;
    #   include fastcgi_params;
    #   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    #   fastcgi_param PATH_INFO $fastcgi_path_info;
    #}

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass php:9000;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $realpath_root;
            internal;
        }


    location ~ \.php$ {
            return 404;
        }

}

我尝试了docker-compose build --no-cache,docker build。 -t simple-app-symfony->没有任何变化。 有什么想法吗? 我认为问题出在卷上,因为我删除了卷的分区,因此容器已更新。

但是我需要卷映射,因为在这种情况下,php需要访问源代码

您正在两个冲突的步骤中更改/var/www/html的内容:

  1. Dockerfile中的COPY指令将构建上下文中的文件复制到容器的/var/www/html文件夹中。
  2. docker-compose中的卷安装指令将卷安装到同一文件夹,这使复制的文件不可见。

要解决此问题,请删除Dockerfile中的COPY指令,然后在docker-compose中使用bind-mount将源代码文件夹安装到容器的/var/www/html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM