1

I wish to install Symfony and use it on a project, but do it without installing it on my system. So I figured it could be done using Docker, yet my efforts to make it work haven't paid off so far. I created a Dockerfile where I tried installing everything I could possibly need and then running Symfony, while I was setting up a simple docker-compose.yml. When I try to up it, the container just exists, and by its log, it seems that Symfony could not be found, even though the image seems to build ok.

So what would be the correct way to accomplish this?

Dockerfile:

FROM php:8.1-apache

RUN a2enmod rewrite
 
RUN apt-get update \
  && apt-get install -y libzip-dev git wget --no-install-recommends \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
 
RUN docker-php-ext-install pdo mysqli pdo_mysql zip;
 
RUN wget https://getcomposer.org/download/2.2.0/composer.phar \
    && mv composer.phar /usr/bin/composer && chmod +x /usr/bin/composer

RUN composer create-project symfony/skeleton:"6.1.*" app

RUN cd /app

CMD ["symfony", "server:start"]

docker-compose.yml:

version: '3.7'
 
services:

db:
    image: mysql:5.7
    environment:
        - MYSQL_ROOT_PASSWORD=somerootpass
        - MYSQL_PASSWORD=somepass
        - MYSQL_DATABASE=dockerizeme_db
        - MYSQL_USER=someuser
web:
    build: .
    ports:
        - 8080:8000
    volumes:
        - './app:/app'
    depends_on:
            - db
3
  • There are tools that already take care of this stuff. Are you doing it as a learning experience or want something that works now? Commented Sep 14, 2022 at 20:34
  • @Alberto Take a look at this project: github.com/tarlepp/symfony-flex-backend webserver, php, datagase and other stuff - are all in docker-compose.yml. Maybe you'll find some inspiration. Commented Sep 14, 2022 at 23:30
  • @msg thanks, but those instructions only go as far as putting local project inside a container, at least as far as I got it Commented Sep 16, 2022 at 19:00

1 Answer 1

1

You have a couple problems here.

First, you did not install the Symfony's CLI in your container, see https://symfony.com/download.

Without this, you can not use the symfony command. The compose create-project command does not install the CLI, it's only creating the framework skeleton.

Next, you are mounting a local folder ./app on your container's /app thus, the result of create project in your Dockerfile is overwritten at run time.

If you want to create the project in your local folder mounted inside the container, you would have to do it in the ENTRYPOINT.

But, since it's something you will most likely want to do only once, if you really do not want anything on your local computer, you could take the following approach.

  1. Temporarily change your command, maybe in your docker-compose.yaml file to ["sleep", "infinity"] and re-up your containers
  2. Run a command docker compose exec web composer create-project symfony/skeleton:"6.1.*" app
  3. Change back your command and re-up your containers one last time

Bind mounts are mounted at run time so they are not yet mounted during your build.

Also, I see that you run Symfony's dev server but are using a Apache PHP image. I would normally do one or the other but not both.

Plus you do a RUN cd /app but the correct way to do that in that context would be WORKDIR /app

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.