Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

php - unsupported option when trying to build docker compose on a Laravel project

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...