I am currently setting up a symfony project with docker and need to run some commands via bin/console like this:

php bin/console doctrine:database:create --if-not-exists

php bin/console doctrine:migrations:migrate

Currently I'm trying to do this with docker-compose exec:

 docker-compose exec app bin/console doctrine:database:create --if-not-exists 

As result, I get this error:

OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"bin/console\": permission denied": unknown

I tried using chmod wihin my Dockerfile, but this did not work:

Dockerfile-php

FROM php:fpm
RUN apt-get update && apt-get install -y --no-install-recommends \
        git \
        libxml2-dev \
    && docker-php-ext-install \
        pdo_mysql
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
COPY . /var/www/project
WORKDIR /var/www/project/

RUN usermod -u 1000 www-data
RUN chown -R www-data:www-data var/cache
RUN chown -R www-data:www-data var/log
RUN chmod +x bin/console

docker-compose.yaml

services:
  app:
    build:
      context: . 
      dockerfile: Dockerfile-php 
    environment: 
      - DATABASE_URL=mysql://xxx:[email protected]:3306/project_db # Connection string for the database
    volumes:
      - ./:/var/www/project/ 
    networks:
      - symfony 
...

Any Ideas, how I can do this?

1 Answers

1
Nico Haase On Best Solutions

As you can see on https://hub.docker.com/_/php/, the docker image you are using (php:fpm) does not contain the CLI version, so you should use another image.

And as Docker allows you to do that, you might use a completely different container to run the CLI version side to side the container running the webserver, with the common directories mounted to both containers. This helps you to better seperate the different parts