dockerfile build error to copy in parent folder - docker

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

Related

Error no such file or directory when docker compose build

$docker-compose build
mv: cannot stat '/root/.symfony/bin/symfony': No such file or directory
ERROR: Service 'www_symfony_colcot' failed to build: The command '/bin/sh -c echo "ServerName localhost" >> /etc/apache2/apache2.conf && apt-get
Normaly auto generated by docker-compose.yml
docker-compose.yml :
version: "3.5"
services:
db_symfony_colcot:
image: mariadb:10.5.13
container_name: db_symfony_colcot
command: [ "--default-authentication-plugin=mysql_native_password" ]
restart: always
environment:
MYSQL_ROOT_PASSWORD: gsbgenerique
MYSQL_DATABASE: colcot
MYSQL_USER: gestionnaire
MYSQL_PASSWORD: gsbgenerique
volumes:
- ./initSQL/:/docker-entrypoint-initdb.d/
- "./datamysql-colcot:/var/lib/mysql"
ports:
- "3311:3306"
networks:
- dev-sym
www_symfony_colcot:
build: php
container_name: www_symfony_colcot
ports:
- "8094:80"
user: 0:0
volumes:
- ./php/vhosts:/etc/apache2/sites-enabled
- /home/marc/Desktop/colcot/colcot-2022/Colcot/:/var/www
restart: always
networks:
- dev-sym
networks:
dev-sym:
volumes:
db-data:
Dockerfile :
FROM php:7.4-apache
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf \
\
&& apt-get update \
&& apt-get install -y --no-install-recommends \
locales apt-utils git libicu-dev g++ libpng-dev libxml2-dev libzip-dev libonig-dev libxslt-dev unzip \
\
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen \
\
&& curl -sS https://getcomposer.org/installer | php -- \
&& mv composer.phar /usr/local/bin/composer \
\
&& curl -sS https://get.symfony.com/cli/installer | bash \
&& mv /root/.symfony/bin/symfony /usr/local/bin \
&& useradd -m symfony -u 1001 \
\
&& docker-php-ext-configure \
intl \
&& docker-php-ext-install \
pdo pdo_mysql opcache intl zip calendar dom mbstring gd xsl \
\
&& pecl install apcu && docker-php-ext-enable apcu
WORKDIR /var/www/
Error caused by line :
&& mv /root/.symfony/bin/symfony /usr/local/bin \
How can i solve this error please. Btw im beginner with docker but this project was working since 5 month ago.
Already try :
Change mariadb version
All php version ( from 5.6 to 8 )
Change dockercompose version
Result : Still not working and same error
The command you are using to install symfony:
curl -sS https://get.symfony.com/cli/installer | bash
Is installing Symfony version 5. The files are located in symfony5 folder (notice the 5):
The Symfony CLI was installed successfully!
Use it as a local file:
/root/.symfony5/bin/symfony
So instead of running mv /root/.symfony/bin/symfony /usr/local/bin (.symfony folder does not exist), you should run:
mv /root/.symfony5/bin/symfony /usr/local/bin
By the way, as of 2022, using this script seems not to be the recommended method anymore: see https://symfony.com/download.
For info, the commit who changes the folder in the script from .symfony to .symfony5 is this one: https://github.com/symfony-cli/symfony-cli/commit/5301ebfa8f5918cae7fa0bf63c86f84dbd70f599.
I will add that in order to understand whether version 5 has changed to some other, you can look at the installer file (https://get.symfony.com/cli/installer) itself. Now (at the time of writing this comment) there is such information:
CLI_CONFIG_DIR=".symfony5"

Error: (root) Additional property laminas is not allowed

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

Generating PHP library with Dockerized gRPC

I'm trying to build a gRPC PHP Client and gRPC NodeJs Server in docker. But the problem is I can't install protoc-gen-php-grpc to my docker server. When I try to run this run this makefile:
proto_from_within_container:
# PHP
protoc /var/www/protos/smellycat.proto \
--php_out=/var/www/php-client/src \
$(: 👇 generate server interface) \
--php-grpc_out=/var/www/php-client/src \
$(: 👇 generates the client code) \
--grpc_out=/var/www/php-client/src \
--plugin=protoc-gen-grpc=/protobuf/grpc/bins/opt/grpc_php_plugin \
--proto_path /var/www/protos
proto:
powershell rm -r -fo php-client/src -ErrorAction SilentlyContinue
powershell New-Item -ItemType Directory -Path php-client/src -Force -ErrorAction SilentlyContinue
docker-compose run grpc-server make proto_from_within_container
With this command: make proto
Getting this error message after docker containers builded:
protoc /var/www/protos/smellycat.proto \
--php_out=/var/www/php-client/src \
\
--php-grpc_out=/var/www/php-client/src \
\
--grpc_out=/var/www/php-client/src \
--plugin=protoc-gen-grpc=/protobuf/grpc/bins/opt/grpc_php_plugin \
--proto_path /var/www/protos
protoc-gen-php-grpc: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--php-grpc_out: protoc-gen-php-grpc: Plugin failed with status code 1.
Makefile:4: recipe for target 'proto_from_within_container' failed
make: *** [proto_from_within_container] Error 1
This is my docker-compose file
version: "3"
services:
grpc-server:
container_name: grpc-server
build:
context: .
dockerfile: Dockerfile-server
working_dir: /var/www
volumes:
- .:/var/www
grpc-client:
image: php:7.4-cli
container_name: grpc-client
build:
context: .
dockerfile: Dockerfile-client
working_dir: /var/www
volumes:
- .:/var/www
command: bash -c [php php_client.php && composer install]
And this is my grpc-server docker file:
FROM node:latest
ENV DEBIAN_FRONTEND=noninteractive
#Versions
ARG PROTOBUF_VERSION=3.14.0
ARG PHP_GRPC_VERSION=1.34.0
# Utils
RUN apt-get update -yqq \
&& apt-get install -yqq wget unzip zlib1g-dev git autoconf libtool automake build-essential software-properties-common curl zip \
&& rm -rf /var/lib/apt/lists/*
# Protobuf
RUN mkdir -p /protobuf
RUN cd /protobuf \
&& wget https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip -O protobuf.zip \
&& unzip protobuf.zip && rm protobuf.zip
# grpc PHP (generate client)
RUN apt-get update -yqq && apt-get upgrade -yqq
RUN apt-get install php php-dev php-pear phpunit zlib1g-dev -yqq
RUN pecl install grpc-${PHP_GRPC_VERSION}
RUN cd /protobuf && git clone -b v${PHP_GRPC_VERSION} https://github.com/grpc/grpc \
&& cd /protobuf/grpc && git submodule update --init
RUN cd /protobuf/grpc && make grpc_php_plugin
ENV PATH "/protobuf/bin:${PATH}"
ENV PATH "/protobuf/grpc/bins/opt:${PATH}"
# NPM Installation
WORKDIR /var/www
COPY . /var/www
RUN npm install
CMD ["node", "server.js"]
Do you have any advice?
After a lot of search and readings, I finally managed to build a full application that communicates with each other.
The problem was at the Makefile, at this step:
--plugin=protoc-gen-grpc=/protobuf/grpc/bins/opt/grpc_php_plugin
I was assigning the wrong path for grpc_php_plugin.
There is my new dockerfile:
FROM php:7.4-cli
# Environment variables
ENV DEBIAN_FRONTEND=noninteractive
# Utils
RUN apt-get update -yqq && \
apt-get upgrade -yqq && \
apt-get install -y unzip build-essential git software-properties-common curl pkg-config zip zlib1g-dev
# Composer installation
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
# Install grpc and probuf with pecl
RUN pecl install grpc && pecl install protobuf
# Enable grpc and protobuf extensions in php.ini file
RUN echo starting && \
docker-php-ext-enable grpc && \
docker-php-ext-enable protobuf
# Install cmake
RUN apt-get update -yqq && apt-get -y install cmake
# Install grpc_php_plugin and protoc
RUN git clone -b v1.36.2 https://github.com/grpc/grpc && \
cd grpc && git submodule update --init && \
mkdir cmake/build && cd cmake/build && \
cmake ../.. && make protoc grpc_php_plugin
# Setting node, protoc and grpc_php_plugin paths
ENV PATH "/grpc/cmake/build:${PATH}"
ENV PATH "/grpc/cmake/build/third_party/protobuf:${PATH}"
# Moving client folder to vm
WORKDIR /var/www
COPY ./client /var/www
# Packages
RUN composer install
# Generate php libraries from proto file
RUN make proto
CMD [ "php", "./handler.php" ]
For my full application, click.

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