Error: (root) Additional property laminas is not allowed - docker

I keep getting this error every time I execute docker-compose up -d command in Windows CLI. Please help me solve this problem. Docker-compose.yml file which I'm using is part of Laminas skeleton application and was prewritten there.
Here is docker-compose.yml code:
laminas:
build: .
dockerfile: Dockerfile
ports:
- "8081:80"
volumes:
- .:/var/www
Here is Dockerfile code:
FROM php:7.3-apache
LABEL maintainer="getlaminas.org" \
org.label-schema.docker.dockerfile="/Dockerfile" \
org.label-schema.name="Laminas MVC Skeleton" \
org.label-schema.url="https://docs.getlaminas.org/mvc/" \
org.label-schema.vcs-url="https://github.com/laminas/laminas-mvc-skeleton"
## Update package information
RUN apt-get update
## Configure Apache
RUN a2enmod rewrite \
&& sed -i 's!/var/www/html!/var/www/public!g' /etc/apache2/sites-available/000-default.conf \
&& mv /var/www/html /var/www/public
## Install Composer
RUN curl -sS https://getcomposer.org/installer \
| php -- --install-dir=/usr/local/bin --filename=composer
###
## PHP Extensisons
###
## Install zip libraries and extension
RUN apt-get install --yes git zlib1g-dev libzip-dev \
&& docker-php-ext-install zip
## Install intl library and extension
RUN apt-get install --yes libicu-dev \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl
WORKDIR /var/www

Related

dockerfile build error to copy in parent folder

My project structure :
- docker-compose.yml
- api
|- composer.json
- php
|- Dockerfile
My Dockerfile in php folder :
FROM php:8.0-fpm
RUN apt update \
&& apt install -y zlib1g-dev g++ git libicu-dev zip libzip-dev zip \
&& docker-php-ext-install intl opcache pdo pdo_mysql \
&& pecl install apcu \
&& docker-php-ext-enable apcu \
&& docker-php-ext-configure zip \
&& docker-php-ext-install zip
WORKDIR /var/www/symfony_docker
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN curl -sS https://get.symfony.com/cli/installer | bash
RUN mv /root/.symfony/bin/symfony /usr/local/bin/symfony
RUN git config --global user.email "you#example.com" \
&& git config --global user.name "Your Name"
COPY ../api/composer.json .
COPY ../api/. .
RUN composer install
My docker-compose :
services:
php:
build:
context: ./php
ports:
- '9000:9000'
I got a error when i start my docker-compose (docker-compose up -d --build)
=> ERROR [ 8/10] COPY ../api/composer.json . 0.0s
=> ERROR [ 9/10] COPY ../api/. .
I cannot copy my composer.json file locally to my container to then install the dependencies

Access site served locally via Laravel Valet from Docker container

I'm trying to get my local dev environment setup using a combination of Docker which is serving a webapp that I'm developing, and Laravel Valet which is serving the API (being served on api.test).
What I can't figure out is how to hit the API from within the Docker container?
Dockerfile:
FROM php:5-apache
WORKDIR /var/www/html
COPY ./default.conf /etc/apache2/sites-available/000-default.conf
RUN apt-get update && \
apt-get -y install curl git libicu-dev libpq-dev zlib1g-dev zip libmcrypt-dev libgd-dev && \
docker-php-ext-install intl mbstring pcntl zip mcrypt && \
usermod -u 1000 www-data && \
usermod -a -G users www-data && \
chown -R www-data:www-data /var/www && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
a2enmod rewrite && \
curl -sL https://deb.nodesource.com/setup_13.x | bash - && \
apt-get install -y nodejs && \
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \
docker-php-ext-install gd
COPY . /var/www/html
docker-compose.yml:
version: '2'
services:
web:
build: .
ports:
- "8090:80"
volumes:
- .:/var/www/html
network_mode: bridge
Ok, finally figured this out thanks to some help from a friend.
I found the IP address of the host: ping host.docker.internal which gave me 192.168.65.2.
Then updated /etc/hosts file in the Docker container with:
192.168.65.2 api.test
(where api.test is the route that the API is being served on my localhost)
Now I can hit api.test from within the Docker container :-)

dockerfile not updating container

I'm working with an app using docker (i'm not super familiar) and I need to add 2 new PHP extensions. I have changed the Dockerfile on an existing image as follows:
FROM php:7.2-fpm
RUN apt-get update
RUN apt-get install -y git unzip
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
RUN apt-get install -y git libpng-dev \
&& docker-php-ext-install gd
RUN apt-get install -y mysql-client \
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
&& docker-php-ext-install pdo_mysql
RUN apt-get install -y libgmp-dev bcmath \
&& docker-php-ext-configure gmp \
&& docker-php-ext-install gmp \
&& docker-php-ext-install bcmath
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
ADD docker/templates/usr/local/etc/php/conf.d/uploads.ini /usr/local/etc/php/conf.d/uploads.ini
My new lines are:
RUN apt-get install -y libgmp-dev bcmath \
&& docker-php-ext-configure gmp \
&& docker-php-ext-install gmp \
&& docker-php-ext-install bcmath
I tried docker-compose restart, I tried docker-compose down followed by docker-compose up, I removed the container entirely and re-created with up. However hard I try, I always get this error when doing a composer require
the requested PHP extension bcmath is missing from your system.
I'm not sure why this is happening. Why won't the extension install, and how come if I completely delete the contents and write garbled text in the Dockerfile, it always runs successfully. Is it caching it?
Can somebody explain how I'd re-provision with the new changes I made?
Snippet of docker-compose.yml:
services:
web:
build:
context: ./
dockerfile: docker/web.docker
working_dir: /var/www
volumes:
- ./:/var/www
ports:
- 81:80
app:
build:
context: ./
dockerfile: docker/app.docker
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "LARAVEL_ENVIRONMENT=local"
You need to rebuild the image
docker-compose build
and next re-run containers
docker-compose up -d

docker The DSN string could not be parsed with CakePHP

I'm configuring CakePHP application with Docker.
I'm new to Docker and this is my first docker-compose.
Dockerfile
FROM php:7.2-apache
LABEL maintainer="Anuj Sharma <contact#anujsh.in>"
# Enable Apache Rewrite + Expires Module
RUN a2enmod rewrite expires
# Install dependencies
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libyaml-dev \
zlib1g-dev \
libicu-dev \
libpq-dev \
libmcrypt-dev \
mysql-client \
g++ \
git \
libzip-dev \
zip \
unzip \
&& rm -r /var/lib/apt/lists/* \
&& pecl install mcrypt-1.0.1 \
&& docker-php-ext-install opcache \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip \
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install mbstring pcntl pdo_mysql pdo_pgsql pgsql \
&& docker-php-ext-enable mcrypt \
&& docker-php-ext-enable intl
# Install composer
#RUN curl -sS https://getcomposer.org/installer | php -- --install -dir=/usr/bin/ --filename=composer
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=2'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
echo 'upload_max_filesize=128M'; \
echo 'post_max_size=128M'; \
echo 'extension=intl.so'; \
} > /usr/local/etc/php/conf.d/php-recommended.ini
RUN pecl install apcu \
&& pecl install yaml \
&& docker-php-ext-enable apcu yaml
# Set our application folder as an environment variable
ENV APP_HOME /var/www/html
# Change uid and gid of apache to docker user uid/gid
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data
# Change the web_root to cakephp /var/www/html/webroot folder
RUN sed -i -e "s/html/html\/webroot/g" /etc/apache2/sites-enabled/000-default.conf
# Copy source files and run composer
COPY . $APP_HOME
# Install all PHP dependencies
RUN composer install --no-interaction
# Change ownership of our applications
RUN chown -R www-data:www-data $APP_HOME
NOTE: I have copied commands from different sources to generate above Dockerfile.
docker-compose.yml
version: "3.1"
# Define all services
services:
# Our service is called CakePHP ;-)
cakephp:
# We want to use the image which is build from our Dockerfile
build: .
# Apache is running on port 80 but we want to expose this to port 4000 on our local machine
ports:
- "4000:80"
# We depending on the mysql backend
depends_on:
- mysql
volumes:
- .:/var/www/html/
environment:
- SECURITY_SALT=070q78he40qfw475q0q7v0wt7vfqw7vw87qw8dpowe7rfpwq437
- DATABASE_URL=mysql
- MYSQL_USERNAME=root
- MYSQL_PASSWORD=root
- MYSQL_DATABASE=cakephp
mysql:
# We use the mysql base image, version 5.7
image: mysql:5.7
# We mount a datavolume to make sure we don't loose data
volumes:
- cap_mysql_data:/var/lib/mysql
# Setting some env vars to create the DB
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=cakephp
volumes:
cap_mysql_data:
When I run
docker-compose build
It all goes well. But when I run to migrate the migrations
docker-compose run cakephp bin/cake migrations migrate
It gives error as
Exception: The DSN string 'mysql' could not be parsed. in [/var/www/html/vendor/cakephp/cakephp/src/Core/StaticConfigTrait.php, line 292]
The app.php file of CakePHP have configuration for datasource
'username' => env('MYSQL_USERNAME', 'root'),
'password' => env('MYSQL_PASSWORD', ''),
'database' => env('MYSQL_DATABASE', 'cakephp'),
'url' => env('DATABASE_URL', null),
The DATABASE_URL environment variable is expected to hold a DSN (data source name) string, mysql isn't such a string, this is what a DSN looks like:
mysql://user:pass#localhost:3306/database?encoding=utf8&timezone=UTC&cacheMetadata=true
The parts are basically as follows:
<driver>://<username>:<password>#<host>:<port>/<database>?<options>
If you don't actually want to use a DSN, then do not specify the DATABASE_URL variable.
See also
Cookbook > Database Access & ORM > Database Basics > Configuration
API > \Cake\Datasource\ConnectionManager::parseDsn()

Build Project inside docker container and share folder in mounted

I use docker-compose to build my containers and on a state I checkout private repository and I build the project inside container with composer.
I have the following structure
- docker-project
-- docker //here I keep the containers
--- apache
---- Dockerfile // the content what I posted
-- docker-compose.yml
-- src //this is the mounted folder where I can work on project
After build I would expect that the build project would show up in the mounted folder but instead I get empty folders here is my compose yml
apache:
container_name: apache2
build:
context: ./docker/apache
ports:
- 80:80
- 443:443
links:
- database
restart: always
volumes:
- ./src:/var/www/
- ./docker/logs/apache2/:/var/log/apache2/
- ~/.ssh/id_rsa:/root/.ssh/id_rsa
- ./docker/apache/sites/:/etc/apache2/sites-enabled
and here I have the docker file
FROM php:7.1-apache
ENV APACHE_DOCUMENT_ROOT /var/www
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl \
openssl \
openssh-server \
sendmail \
sendmail-bin \
mailutils \
libicu-dev \
libmemcached-dev \
libz-dev \
libpq-dev \
libjpeg-dev \
libfreetype6-dev \
libssl-dev \
libmcrypt-dev \
libxml2-dev \
libbz2-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
zlib1g-dev \
libicu-dev \
g++ \
libxml2-dev \
git \
&& rm -rf /var/lib/apt/lists/*
# Install various PHP extensions which are required to build project
RUN docker-php-ext-configure bcmath --enable-bcmath \
&& docker-php-ext-configure pcntl --enable-pcntl \
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql \
&& docker-php-ext-configure pdo_pgsql --with-pgsql \
&& docker-php-ext-configure mbstring --enable-mbstring \
&& docker-php-ext-configure soap --enable-soap \
&& docker-php-ext-install \
bcmath \
json \
intl \
mbstring \
mcrypt \
mysqli \
pcntl \
pdo_mysql \
pdo_pgsql \
soap \
sockets \
zip \
&& docker-php-ext-configure gd \
--enable-gd-native-ttf \
--with-jpeg-dir=/usr/lib \
--with-freetype-dir=/usr/include/freetype2 && \
docker-php-ext-install gd
##install xdebug and enable it. We need this for php unit coverage
RUN yes | pecl install xdebug \
&& docker-php-ext-enable xdebug
RUN yes | pecl install mongodb \
&& docker-php-ext-enable mongodb
RUN update-ca-certificates
# install composer to can install dependencies
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
&& php -r "unlink('composer-setup.php');"
RUN mkdir /root/.ssh
RUN rm -rf /var/www/project
WORKDIR /var/www/
RUN git checkout path/to/repo
RUN ls -l /var/www
WORKDIR /repo
RUN composer install
RUN ls -l
on docker-compose build I see that the project will be builded but on
docker-compose upthe folder is empty
What I'm missing in this case?
You are mounting a volume on /var/www when starting the container.
/var/www will be the same as ./src/www on the host machine, replacing anything that was added to /var/www during the build of the image.
Consider using the composer docker image or make sure to install the dependencies to another directory. Check out the vendor_dir key in composer.json
Example:
composer.json
{
"require": {
},
"config": {
"vendor-dir": "/var/www/vendor/"
}
}
Docker image build:
...
RUN mkdir -p /var/www/vendor/
COPY composer.json /var/www/vendor/
RUN cd /var/www/vendor/ && composer install
RUN mkidr -p /var/www/app
...
docker-compose.yml
volumes:
- ./src:/var/www/app
I could give a way of currently we are working. Rather cloning the repo like this what we do, we clone the repo in the local machine.
You have standard docker image that you have created from
php:7.1-apache with required softwares that you need to run the project.
Then you clone your project to you host machine.(think into src folder)
You run the composer install locally.
Then as you have defined the docker-compose.yml mount your src folder into /var/www/

Resources