Kubernetes: Can't Run Kompose Up While Deploying Laravel App - docker

i'm new in DevOps tried to deploying Laravel app (from my bootcamp source code) to Kubernetes in my local machine (CentOS 7), i have problem when convert my docker-compose.yml with Kompose especially in volume mount. Can you tell me how to solve this problem? I have tried troubleshoot but not succeeded.
Here is my docker-compose.yml file:
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.22
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: nightraven
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
and this is Dockerfile i create for Laravel app:
FROM php:7.2-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
And this is the error:
https://i.stack.imgur.com/LtKka.png
it's said
FATA Error while deploying application: k.Transform failed: Unable to
build Docker image for service app: Unable to create a tarball:
archive/tar: write too long

Related

Docker and Symfony: Composer install does not launch

I use the Docker environment with the Symfony framework. I created my own Dockerfile and my own docker-compose.yml file.
The problem is that the 'compose install' command does not run when I run the 'docker compose up' command.
Here is the code of my dockerfile :
ARG PHP_VERSION=8.1
FROM php:${PHP_VERSION}-fpm
RUN apt-get update && apt-get install -y
# Install modules
RUN apt-get install -y --no-install-recommends \
git \
zlib1g-dev \
libxml2-dev \
libzip-dev \
libpq-dev \
nano \
&& docker-php-ext-install \
zip \
intl \
pdo \
mysqli \
pdo_mysql \
opcache
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
# Install Symfony CLI
RUN curl -sS https://get.symfony.com/cli/installer | bash
RUN mv /root/.symfony/bin/symfony /usr/local/bin/symfony
# Copy the application files
COPY . /var/www/html
# Install dependencies from composer.json
RUN composer install
# Set the default directory inside the container
WORKDIR /var/www/html
Here is the code of my yml file:
version: '3.8'
networks:
myapp:
services:
db:
container_name: ${APP_NAME}-db
image: 'mariadb:latest'
restart: always
ports:
- 3306:3306
volumes:
- './.docker/mysql:/var/lib/mysql'
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASS}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASS}
MYSQL_DATABASE: ${MYSQL_DB}
networks:
- myapp
php:
container_name: ${APP_NAME}-php
build: ./docker/php
volumes:
- './:/var/www/html'
environment:
- APP_ENV=${APP_ENV}
- APP_SECRET=${APP_SECRET}
depends_on:
- db
networks:
- myapp
nginx:
container_name: ${APP_NAME}-nginx
image: 'nginx:latest'
ports:
- 8080:80
#- 8443:443 # if https config
expose:
- 80
volumes:
- ./:/var/www/html
- ./docker/nginx/conf.d:/etc/nginx/conf.d
depends_on:
- php
networks:
- myapp
phpmyadmin:
image: 'phpmyadmin/phpmyadmin:latest'
container_name: ${APP_NAME}-phpmyadmin
ports:
- 8000:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASS}
networks:
- myapp
Do you know where the problem is? I copy well the root files (where is my composer.json file) to the container folder (/var/www/html). My files are well present when I do the command 'docker-compose exec php /bin/bash' then 'ls'.
I have the following structure:
- MY-PROJECT
> docker/
> nginx/
> php
> Dockerfile
.env
composer.json
docker-compose.yml
I tried several methods, including moving the commands into the file or putting the 'compose install' command in the .yml file, but I don't think this is the solution.
I would suggest that you move your Dockerfile to the root directory of your project and set the context to .
php:
container_name: ${APP_NAME}-php
build: .
volumes:
- './:/var/www/html'
environment:
- APP_ENV=${APP_ENV}
- APP_SECRET=${APP_SECRET}
depends_on:
- db
networks:
- myapp
You need also to change some order inside your Dockerfile and for Symfony cli you need to change it:
RUN mv /root/.symfony5/bin/symfony /usr/local/bin/symfony
Last, if you are new on this i would suggest that you use the documentation from Symfony:
https://symfony.com/doc/current/setup/docker.html
You can then adapt it on your need and add phpMyAdmin etc...

Docker-Compose Apache+PHP+React+MySQL and Laravel

I'm trying to mount a docker-compose with its respective dockerfile to have a project with a /backend/ folder where an API with laravel will go and then a /frontend/ folder where a react frontend goes.
The goal is to build on it so I need to use volumes with persistent data.
The build does it perfectly and I can enter each of the dockers, the problems I have are:
The volumes are not persistent, that is, I make a change in the frontend directory (react) and I don't see the changes, I only see them if I do another build.
From the backend container I want to be able to access the DB to launch the Laravel migrations and I get an error that it can't find the schema.
Docker-compose.yaml
version: '3.7'
services:
frontend:
build:
context: ./app-frontend
ports:
- "81:80"
networks:
- app-network
backend:
build:
context: ./app-backend/
restart: unless-stopped
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
working_dir: /var/www
volumes:
- ./app-backend:/var/www
ports:
- "8001:8000"
networks:
- app-network
- db
appdb:
image: mysql:5.7
restart: unless-stopped
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
volumes:
- ./initdb:/docker-entrypoint-initdb.d
ports:
- "3307:3306"
networks:
- db
networks:
app-network:
driver: bridge
db:
Dockerfile backend
FROM php:7.4-apache
RUN a2enmod rewrite
RUN apt-get update && apt-get install -y \
libzip-dev \
zlib1g-dev \
libicu-dev \
libxml2-dev \
libpq-dev \
vim \
libpng-dev \
&& docker-php-ext-install pdo pdo_mysql zip intl xmlrpc soap opcache \
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
COPY docker/php/https://php.ini /usr/local/etc/php
COPY docker/apache/https://apache2.conf /etc/apache2/https://apache2.conf
COPY docker/apache/https://vhost.conf /etc/apache2/sites-available/000-https://default.conf
ENV COMPOSER_ALLOW_SUPERUSER 1
COPY . /var/www
RUN chown -R www-data:www-data /var/www/html
WORKDIR /var/www
RUN composer install
Dockerfile frontend
FROM node:13.10.1-alpine
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
ENTRYPOINT npm start

SQLSTATE[HY000] [2002] Connection refused with docker-compose on travis only for symfony phpunit test

I have a docker compose setup for symfony that is working locally but when i run the same thing on Travis CI, I am getting SQLSTATE[HY000] [2002] Connection refused despite setting the host in my .env to mysql.
.env.test
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
DATABASE_URL=mysql://admin:password#mysql:3306/app?serverVersion=5.7
docker-compose.yml
version: '3'
services:
web:
image: nginx:alpine
restart: always
tty: true
depends_on:
- php
ports:
- "80:80"
- "443:443"
volumes:
- ./src:/usr/src/app
- ./docker/nginx/conf.d/:/etc/nginx/conf.d/
php:
build:
dockerfile: ./docker/php/Dockerfile
context: ./
working_dir: /usr/src/app
restart: always
tty: true
depends_on:
- mysql
volumes:
- ./src:/usr/src/app
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
mysql:
image: mysql:8
restart: always
tty: true
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: app
MYSQL_USER: admin
MYSQL_PASSWORD: password
volumes:
- ./docker/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
- ./docker/mysql/init.sql:/docker-entrypoint-initdb.d/init.sql
- mysqldata:/var/lib/mysql
volumes:
mysqldata:
docker/php/Dockerfile
FROM php:7.4-fpm
RUN docker-php-ext-install pdo_mysql
RUN pecl install apcu
RUN pecl install mailparse
RUN apt-get update && \
apt-get install -y \
libzip-dev
RUN docker-php-ext-install zip
RUN docker-php-ext-enable apcu
RUN docker-php-ext-enable mailparse
RUN apt-get update
RUN apt-get install unzip
RUN apt-get -y --no-install-recommends install git \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /usr/src/app
.travis.ci
language: generic
sudo: required
services:
- docker
before_install:
- docker-compose up -d
script:
- docker-compose exec php composer install && docker-compose exec php vendor/bin/phpunit tests/
Travis error
PHPUnit 9.2.3 by Sebastian Bergmann and contributors.
EEEEEEEEEEEEEEEEFEFEEEEEEE 26 / 26 (100%)
Time: 00:01.095, Memory: 46.50 MB
There were 24 errors:
1) App\Tests\CompanyTemplateApiTest::testCreateCompanyTemplate
Doctrine\DBAL\Exception\ConnectionException: An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused
/usr/src/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:93
/usr/src/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:169
/usr/src/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:157
/usr/src/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php:28
/usr/src/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:362
/usr/src/app/vendor/liip/test-fixtures-bundle/src/Services/DatabaseTools/ORMDatabaseTool.php:74
/usr/src/app/vendor/liip/test-fixtures-bundle/src/Services/DatabaseTools/ORMDatabaseTool.php:102
/usr/src/app/vendor/liip/test-fixtures-bundle/src/Test/FixturesTrait.php:89
/usr/src/app/tests/Controller/CompanyTemplateApiTest.php:37
/usr/src/app/tests/Traits/LoginTrait.php:11
/usr/src/app/tests/Controller/CompanyTemplateApiTest.php:43
This same error repeats for almost every test.

Docker: need to persist folder in symfony project

I'm trying to dockerize my Symfony project.
In this project, I have a folder under: public/fichiersflux/
"fichiersflux" is a folder with persistent data (img, pdf...)
Here is the docker-compose.yml:
version: '3.7'
services:
mariadb:
image: mariadb:10.4
restart: always
environment:
MYSQL_ROOT_PASSWORD: zfezZEFfz4e1589fze
MYSQL_DATABASE: 1c1t
MYSQL_USER: 1c1t
MYSQL_PASSWORD: fez45FZE1fez0fzefF!
ports:
- 3306:3306
php:
image: php:7.4
build:
context: .
dockerfile: docker/php/Dockerfile
restart: on-failure
user: 1000:1000
nginx:
image: nginx:1.17-alpine
restart: on-failure
volumes:
- './app/public/:/usr/src/app'
- './docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro'
ports:
- 8080:80
depends_on:
- php
And my Dockerfile:
# ./docker/php/Dockerfile
FROM php:7.4-fpm
RUN docker-php-ext-install pdo_mysql
RUN pecl install apcu
RUN apt-get update && \
apt-get install -y \
zlib1g-dev
RUN apt-get install -y \
libzip-dev \
libicu-dev \
zip \
&& docker-php-ext-install zip
RUN docker-php-ext-enable apcu \
&& docker-php-ext-install intl
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /usr/src/app
COPY app/ /usr/src/app
RUN chown -R 1000:1000 /usr/src/app
RUN PATH=$PATH:/usr/src/apps/vendor/bin:bin
The problem is, when I build my docker containers, the folder /usr/src/app/ is apparently re-created.. and I loose all data inside public/fichiersflux
How can I persist public/fichiersflux folder ?
Best regards :)
You could just add volumes on php services, to mount your target folder.
version: '3.7'
services:
mariadb:
image: mariadb:10.4
restart: always
environment:
MYSQL_ROOT_PASSWORD: zfezZEFfz4e1589fze
MYSQL_DATABASE: 1c1t
MYSQL_USER: 1c1t
MYSQL_PASSWORD: fez45FZE1fez0fzefF!
ports:
- 3306:3306
php:
image: php:7.4
build:
context: .
dockerfile: docker/php/Dockerfile
volumes:
- '../app/public/fichiersflux:/usr/src/app/fichiersflux'
restart: on-failure
user: 1000:1000
nginx:
image: nginx:1.17-alpine
restart: on-failure
volumes:
- './app/public/:/usr/src/app'
- './docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro'
ports:
- 8080:80
depends_on:
- php

My Docker Compose File is not working properly

hi how are you guys i have 2 docker-compose file but both files are not run properly i face this
enter image description here
error please tell me any body how to fix it i give u a compose file content
(COMPOSE FILE 1)
db:
build: ./mysql
volumes:
- /opt/containers/personal/mysql:/var/lib/mysql
web:
build: ./web
ports:
- 80:80
volumes:
- /opt/containers/personal/php:/var/www/html
links:
- db:db
(COMPOSE FILE 2)
version: "3"
services:
nginx:
build: ./nginx
ports:
- 80:80
- 443:443
volumes:
- /opt/containers/personal/nginx/certs:/certs
depends_on:
- web
networks:
- webdbnet
web:
build: ./web
volumes:
# Example of host volume mounted in container
# - /opt/containers/personal/php:/var/www/html
# Example of docker volume mounted in container
- web-data:/var/www/html
networks:
- webdbnet
db:
# build: ./mysql
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
volumes:
- /opt/containers/personal/mysql:/var/lib/mysql
networks:
- webdbnet
networks:
webdbnet:
volumes:
web-data:
(AND THIS IS MY BUILD DOCKER FILE CONTENT)
FROM php:7-apache
RUN apt-get update && apt-get install -y \
libmcrypt-dev \
libfreetype6-dev \
libjpeg-dev \
libpng-dev \
&& a2enmod rewrite expires \
&& pecl install mcrypt-1.0.1 \
&& docker-php-ext-install gd mysqli opcache iconv \
&& docker-php-ext-configure gd \
--with-freetype-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
&& docker-php-ext-enable mcrypt mysqli
COPY index.html /var/www/html/
COPY index.php /var/www/html/
Sorry for my bad english
It looks like you are running the wrong version of PHP for mcrypt.
Try replacing
FROM php:7-apache
with
FROM php:7.2.14-apache-stretch
In your build file.
php:7-apache is taking you to the latest version, which is 7.3.1 and mcrypt seems to want 7.2.*
When you use official image for php and for this example try to install pecl install mcrypt-1.0.1 after that command you'll need to add this line to
RUN pecl install mcrypt
RUN echo "extension=mcrypt.so" >> /usr/local/etc/php/conf.d/docker-php-ext-intl.ini
Only extension installed via docker-php-ext-install are not required to enable with *.so file
I hope this helps..

Resources