Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker execution of Symfony commands: Permission denied

Tags:

docker

symfony

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:xxx@db:3306/project_db # Connection string for the database
    volumes:
      - ./:/var/www/project/ 
    networks:
      - symfony 
...

Any Ideas, how I can do this?

like image 219
pguetschow Avatar asked Apr 25 '19 14:04

pguetschow


2 Answers

I was having the same problem but running this command in my terminal solved the problem:

chmod +x bin/console

chmod +x on a file means, that you'll make it executable.

like image 137
Keutelvocht Avatar answered Oct 30 '22 18:10

Keutelvocht


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

like image 30
Nico Haase Avatar answered Oct 30 '22 18:10

Nico Haase