curuba
curuba

Reputation: 577

Docker-compose "no such service"

I have an error launching docker-compose up -d with this docker-compose.yml file: no such service: php-c

It used to work and I didn't change anything. I didn't have any docker update in the meantime either.

If I remove container_name key then I have the same error displayed with the name which is auto-generated.

I am using wsl2 and docker 20.10.8.

version: '3'

services:
    db:
        image: mysql:5.7
        container_name: db-c
        ports:
            - 3307:3306
        volumes:
            - "./.data/db:/var/lib/mysql"
        environment:
            MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
            MYSQL_DATABASE: ${MYSQL_DATABASE}
            MYSQL_USER: ${MYSQL_USER}
            MYSQL_PASSWORD: ${MYSQL_PASSWORD}

    php:
        build:
            context: php7-fpm
            args:
                TIMEZONE: ${TIMEZONE}
                username: ${username}
        container_name: php-c
        volumes:
            - ${SYMFONY_APP_PATH}:/var/www/symfony
            - ./logs/symfony/:/var/www/symfony/var/logs
        environment:
            - XDEBUG_REMOTE_HOST=host.docker.internal
            - PHP_IDE_CONFIG=serverName=symfony.local
        user: 1000:1000

    nginx:
        build: nginx
        container_name: nginx-c
        ports:
            - 80:80
        volumes_from:
            - php
        volumes:
            - ./logs/nginx/:/var/log/nginx

Here is the Dockerfile.

# See https://github.com/docker-library/php/blob/master/7.1/fpm/Dockerfile
FROM php:7.3-fpm
ARG TIMEZONE
ARG username=bastien

MAINTAINER Maxence POUTORD <[email protected]>

RUN apt-get update && apt-get install -y \
    openssl \
    git \
    unzip \
    libicu-dev \
    sudo \
    lsof \
    zlib1g-dev \
    libzip-dev \
    iputils-ping

# Install GD
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version

# Set timezone
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone
RUN printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini
RUN "date"

# Type docker-php-ext-install to see available extensions
RUN docker-php-ext-install pdo pdo_mysql zip


# install xdebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN cd /usr/local/etc/php/conf.d/ && \
  echo 'memory_limit = 1G' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini
COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
#RUN echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# & echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# & echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# & echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# & echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# & echo "xdebug.idekey=\"PHPSTORM\"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# & echo "xdebug.remote_port=9001" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# CREATE USER FOR $username

RUN useradd --create-home --shell /bin/bash -u 1000 $username

USER $username

RUN mkdir /home/$username/.ssh \
&& chmod 700 /home/$username/.ssh 

COPY .bashrc /home/$username/.bashrc
COPY config /home/$username/.ssh/config


WORKDIR /var/www/symfony

[EDIT]
When I use restart, this works... I really don't understand what's going on.

docker-compose restart

Upvotes: 1

Views: 16153

Answers (2)

Christoph Mueller
Christoph Mueller

Reputation: 101

I had the same problem.
It seems that the volumes_from configuration is the source of the problem. (might be a docker-compose bug)

Replacing volumes_from with volumes did the trick for me.

Try to use the following for your nginx service configuration:

    nginx:
        build: nginx
        container_name: nginx-c
        ports:
            - 80:80
        volumes:
            - ${SYMFONY_APP_PATH}:/var/www/symfony
            - ./logs/symfony/:/var/www/symfony/var/logs
            - ./logs/nginx/:/var/log/nginx

Upvotes: 3

blackbird
blackbird

Reputation: 146

[EDIT] : better answer

Please : replace php7-form by ./php7-form

   context: ./php7-fpm

it worked for me locally using docker-compose up --build with the following example:

version: '3'

services:
    php:
      build:
       context: ./php7-form
      environment:
        - XDEBUG_REMOTE_HOST=host.docker.internal
        - PHP_IDE_CONFIG=serverName=symfony.local
      user: 1000:1000

[previous answer]

At the moment no image exists for your service. You don't have an image in the "php" service.

you need to add an image in your docker-compose file bellow php: as you did for your db service :

      php:
        image: <your_image_name>

Btw you will have the same problem with the nginx service...

Upvotes: 2

Related Questions