1

I am following this tutorial to install and set up Laravel with Docker-Compose. I want to build an image that is ready to use for any site that has the pre-installed software dependencies. However, this is my first time moving to Docker.

I have cloned my repository into my /var/www as my FQDNS. My Laravel files are now in /var/www/example.co.uk. I have altered my .env to use the DB_DATABASE=db and set the corresponding user and password I'd like to use.

My Dockerfile now looks like this:

FROM php:7.4-fpm

# Arguments defined in docker-compose.yml
ARG user
ARG uid

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
    chown -R $user:$user /home/$user

# Set working directory
WORKDIR /var/www/example.co.uk

USER $user

My docker-compose.yml now looks like this:

version: "3.7"
services:
  app:
    build:
      args:
        user: iezonweb
        uid: 1001
      context: ./
      dockerfile: Dockerfile
    image: iezonweb
    container_name: iezonweb-app
    restart: unless-stopped
    working_dir: /var/www/example.co.uk
    volumes:
      - ./:/var/www/example.co.uk
    networks:
      - iezonweb

  db:
    image: mysql:5.7
    container_name: iezonweb-db
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_USER: ${DB_USERNAME}
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    volumes:
      - ./docker-compose/mysql:/docker-entrypoint-initdb.d
    networks:
      - iezonweb

  nginx:
    image: nginx:alpine
    container_name: iezonweb-nginx
    restart: unless-stopped
    ports:
      - 8000:80
    volumes:
      - ./:/var/www/example.co.uk
      - ./docker-compose/nginx:/etc/nginx/conf.d/
    networks:
      - iezonweb

networks:
  iezonweb:
    driver: bridge

When I run the following command:

$ docker-compose build app

I get the following

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.app.build contains unsupported option: 'container_name' error:

I looked through SO to find any corresponding issues, which lead me to removing this line. However, it then fails with another unsupported option: image and each removal, just continues this chain of unsupported option.

Any help would be appreciated.

Update - My current versions of docker and docker compose are as followed:

$ docker-compose version

docker-compose version 1.27.4, build 40524192
docker-py version: 4.3.1
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

$ sudo docker version

Client: Docker Engine - Community
 Version:           20.10.2
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        2291f61
 Built:             Mon Dec 28 16:17:43 2020
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.2
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       8891c58
  Built:            Mon Dec 28 16:15:19 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.3
  GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc:
  Version:          1.0.0-rc92
  GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
2
  • Can't reproduce locally. What is your docker-compose version? Commented Jan 12, 2021 at 10:32
  • Hi, thanks for your comment. I've updated my question with my current versions @anemyte Commented Jan 12, 2021 at 10:36

1 Answer 1

1

There's most certainly an indentation issue in your docker-compose.yml. YAML relies heavily on space indentation to define a dictionary-like structure.

services.app.build contains unsupported option: 'container_name'

Somehow container_name is parsed as a sub-element of services.app.build This means the error is around this code block:

services:
  app:
    build:
      args:
        user: iezonweb
        uid: 1001
      context: ./
      dockerfile: Dockerfile
    container_name: iezonweb-app

In this example, it's correct as container_name is sub-element of app. However, the docker-compose.yml probably has a small indentation error such as:

services:
  app:
    build:
      args:
        user: iezonweb
        uid: 1001
      context: ./
      dockerfile: Dockerfile
      # Mind number of space: container_name is now sub-elements
      # of build - which is invalid
      container_name: iezonweb-app

Make sure you do not have a mix of tabs and spaces which may be treated by your editor differently and make some elements appear at the same level.

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

1 Comment

Thank-you! This fixed my issue, I had no clue it needed to be indented correctly. Thankyou

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.