dunglas / symfony-docker

A Docker-based installer and runtime for Symfony. Install: download and `docker compose up`.
https://dunglas.dev/2021/12/symfonys-new-native-docker-support-symfony-world/
2.6k stars 778 forks source link

Changes on project does not impact the result page #138

Closed rsida closed 3 years ago

rsida commented 3 years ago

Hello, I'm a bit new on Docker so maybe it's just a misconfiguration but it looks weird. I actually success to install and launch docker and when I go through https://localhost it work great. And now, when I create a controller (I do required minimal config for an website) with it's config and go through https://localhost/my/route or https://localhost/index.php/my/route I got a 404 not found. But when I do bin/console debug/router my route is defined.

Here is my docker-compose.yml:

version: "3.4"

services:
  php:
    build:
      context: .
      target: symfony_php
      args:
        SYMFONY_VERSION: ${SYMFONY_VERSION:-}
        STABILITY: ${STABILITY:-stable}
    restart: unless-stopped
    volumes:
      - php_socket:/var/run/php
    healthcheck:
      interval: 10s
      timeout: 3s
      retries: 3
      start_period: 30s
    environment:
      # Run "composer require symfony/orm-pack" to install and configure Doctrine ORM
      DATABASE_URL: postgresql://${POSTGRES_USER:-symfony}:${POSTGRES_PASSWORD:-ChangeMe}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-13}
      # Run "composer require symfony/mercure-bundle" to install and configure the Mercure integration
      MERCURE_PUBLISH_URL: ${MERCURE_URL:-http://caddy/.well-known/mercure}
      SYMFONY_VERSION:

  caddy:
    build:
      context: .
      target: symfony_caddy
    depends_on:
      - php
    environment:
      SERVER_NAME: ${SERVER_NAME:-localhost, caddy:80}
      MERCURE_PUBLISHER_JWT_KEY: ${MERCURE_PUBLISHER_JWT_KEY:-!ChangeMe!}
      MERCURE_SUBSCRIBER_JWT_KEY: ${MERCURE_SUBSCRIBER_JWT_KEY:-!ChangeMe!}
    restart: unless-stopped
    volumes:
      - php_socket:/var/run/php
      - caddy_data:/data
      - caddy_config:/config
    ports:
      # HTTP
      - target: 80
        published: 80
        protocol: tcp
      # HTTPS
      - target: 443
        published: 443
        protocol: tcp
      # HTTP/3
      - target: 443
        published: 443
        protocol: udp

###> doctrine/doctrine-bundle ###
  database:
    image: postgres:${POSTGRES_VERSION:-13}-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-app}
      # You should definitely change the password in production
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-ChangeMe}
      POSTGRES_USER: ${POSTGRES_USER:-symfony}
    volumes:
      - db-data:/var/lib/postgresql/data:rw
      # You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
      # - ./docker/db/data:/var/lib/postgresql/data:rw
###< doctrine/doctrine-bundle ###

volumes:
  php_socket:
  caddy_data:
  caddy_config:

###> doctrine/doctrine-bundle ###
  db-data:
###< doctrine/doctrine-bundle ###

And my .env:

APP_ENV=dev
APP_SECRET=d0e86d6cd2bd0481f62f4ca8fa2530f9
maxhelias commented 3 years ago

Hi, It's a bit vague as a problem, that may be a lot of things. Start by interpreting the docker logs to know if you are accessing them when there is an HTTP call

rsida commented 3 years ago

``I got this when tried to go to "/_profiler": Capture d’écran 2021-05-03 à 20 36 29 And this when I go through "https://localhost/front/test": Capture d’écran 2021-05-03 à 20 38 56 Here is my composer.json (just in case of):

{
  "type": "project",
  "name": "wayet/core",
  "description": "none",
  "license": "proprietary",
  "minimum-stability": "dev",
  "prefer-stable": true,
  "require": {
    "php": ">=8.0",
    "ext-ctype": "*",
    "ext-iconv": "*",
    "composer/package-versions-deprecated": "1.11.99.1",
    "doctrine/annotations": "^1.0",
    "doctrine/doctrine-bundle": "^2.3",
    "doctrine/doctrine-migrations-bundle": "^3.1",
    "doctrine/orm": "^2.8",
    "phpdocumentor/reflection-docblock": "^5.2",
    "sensio/framework-extra-bundle": "^6.1",
    "symfony/asset": "5.2.*",
    "symfony/console": "5.2.*",
    "symfony/debug-bundle": "5.2.*",
    "symfony/dotenv": "5.2.*",
    "symfony/expression-language": "5.2.*",
    "symfony/flex": "^1.3.1",
    "symfony/form": "5.2.*",
    "symfony/framework-bundle": "5.2.*",
    "symfony/http-client": "5.2.*",
    "symfony/intl": "5.2.*",
    "symfony/mailer": "5.2.*",
    "symfony/mime": "5.2.*",
    "symfony/monolog-bundle": "^3.7",
    "symfony/notifier": "5.2.*",
    "symfony/process": "5.2.*",
    "symfony/property-access": "5.2.*",
    "symfony/property-info": "5.2.*",
    "symfony/proxy-manager-bridge": "5.2.*",
    "symfony/security-bundle": "5.2.*",
    "symfony/serializer": "5.2.*",
    "symfony/stopwatch": "^5.2",
    "symfony/string": "5.2.*",
    "symfony/translation": "5.2.*",
    "symfony/twig-bundle": "^5.2",
    "symfony/validator": "5.2.*",
    "symfony/var-dumper": "5.2.*",
    "symfony/web-link": "5.2.*",
    "symfony/web-profiler-bundle": "^5.2",
    "symfony/yaml": "5.2.*",
    "twig/extra-bundle": "^2.12|^3.0",
    "twig/twig": "^2.12|^3.0"
  },
  "config": {
    "optimize-autoloader": true,
    "preferred-install": {
      "*": "dist"
    },
    "sort-packages": true
  },
  "autoload": {
    "psr-4": {
      "App\\": "src/"
    }
  },
  "autoload-dev": {
    "psr-4": {
      "App\\Tests\\": "tests/"
    }
  },
  "replace": {
    "symfony/polyfill-ctype": "*",
    "symfony/polyfill-iconv": "*",
    "symfony/polyfill-php72": "*"
  },
  "scripts": {
    "auto-scripts": {
      "cache:clear": "symfony-cmd",
      "assets:install %PUBLIC_DIR%": "symfony-cmd"
    },
    "post-install-cmd": [
      "@auto-scripts"
    ],
    "post-update-cmd": [
      "@auto-scripts"
    ]
  },
  "conflict": {
    "symfony/symfony": "*"
  },
  "extra": {
    "symfony": {
      "allow-contrib": false,
      "require": "5.2.*",
      "docker": true
    }
  },
  "require-dev": {
    "symfony/maker-bundle": "^1.30"
  }
}

And the result of my debug:router: Capture d’écran 2021-05-03 à 20 41 56

rsida commented 3 years ago

Ok, I think I got something. My changes is not apply to the server. I try to put a die() inside my 'public/index.php' file and the refresh still display the default Symfony page. Same after a docker restart. Maybe I miss something. Can someone confirm me that, after launching Docker, I could just update the project folder. Like if my project is in /home/admin/my_project, if I do docker-composer up, then I could directly update /home/admin/my_project without enter inside the PHP container, right ?

BaptisteCrouzet commented 3 years ago

Maybe I miss something. Can someone confirm me that, after launching Docker, I could just update the project folder. Like if my project is in /home/admin/my_project, if I do docker-composer up, then I could directly update /home/admin/my_project without enter inside the PHP container, right ?

The usual way want that when you edit your project, you can test the changes in your browser throught the running docker instance. You don't have to enter in your container.

I have no idea about your problem, you are on a recent version, your docker-compose file seems to be like the default one with a DB, no problem here I think. Maybe cache ?

rsida commented 3 years ago

That's really weird, I have to make docker-compose up --build each time I made change to work. EDIT: A little information about my env. I'm on a MAC using Docker Desktop version 3.3.1.

rowanparker commented 3 years ago

Are you actually using docker-compose or the new docker compose method?

In the new docker compose method there is a bug with the override file not being applied. Which means the volume entry ./:/srv/app:rw,cached would not work and therefore your files won't sync across. I had this issue today.

https://github.com/docker/compose-cli/issues/1546

rsida commented 3 years ago

I actually try both but I'm using the Docker Desktop 3.3.2 (I try 3.3.1 too) and there is a chance that one using the other. I mean docker-compose used docker compose internally I don't know. Any way I'll try solution given in the topic you linked 👍🏽

rsida commented 3 years ago

Ok you are right. I made a little tool to help me with some commands and I put docker compose one. Using docker-compose looks good now. Thanks a lot !