Docker: need to persist folder in symfony project - docker

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

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

My web turn on witch docker-compose.yml but not my dockerfile

I work on a deployement of Prestashop image but when i use docker-compose up -d --build it work. I have access to Prestashop install page. But when i do build -t prestashop:latest . to build it and use docker run -d --name prestashop -p 80:80 prestashop:latest to run it. I fall on the apache homepage. Thank you in advance
Dockerfile
FROM ubuntu:18.04
RUN \
sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list && \
apt-get update && \
apt-get -y upgrade && \
apt-get install -y build-essential && \
apt-get install -y software-properties-common && \
apt-get install -y byobu curl git htop man unzip vim wget && \
rm -rf /var/lib/apt/lists/*
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get upgrade
RUN apt-get install -y apache2 libapache2-mod-php
RUN apt install -y php unzip
RUN apt-get install -y php-cli php-common php-mbstring php-gd php-intl php-xml php-mysql php-zip php-curl php-xmlrpc
COPY . /var/www/html:rw
COPY ./config/presta.conf /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite
WORKDIR /var/www/html
EXPOSE 80
CMD apachectl -D FOREGROUND
docker-compose.yml
version: '2'
services:
mysql:
image: mysql:5.7
env_file:
- .env
volumes:
- ./.docker/data/mysql/:/var/lib/mysql
- ./.docker/logs/mysql/:/var/log/mysql
ports:
- "3306:3306"
container_name: presta_mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8080:80
env_file:
- .env
environment:
PMA_HOST: mysql
VIRTUAL_HOST: phpmyadmin.presta.local
container_name: presta_phpmyadmin
app_dev:
container_name: presta_app
build: .
environment:
- VIRTUAL_HOST=app.presta.local
volumes :
- ./:/var/www/html:rw
restart: always
ports:
- 80:80
links:
- "mysql:presta_mysql"
Before you go into it, I recommend you to read docker documentation.
There are a few main topics you need to understand first:
https://docs.docker.com/storage/volumes/
version: '2'
services:
mysql:
image: mysql:5.7
env_file:
- .env
volumes:
- "./.docker/data/mysql/:/var/lib/mysql:rw"
- "./.docker/logs/mysql/:/var/log/mysql:rw"
ports:
- "3306:3306"
container_name: presta_mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- "8080:80"
env_file:
- .env
environment:
PMA_HOST: mysql
VIRTUAL_HOST: phpmyadmin.presta.local
container_name: presta_phpmyadmin
app_dev:
container_name: presta_app
build: .
environment:
- VIRTUAL_HOST=app.presta.local
volumes :
- "./:/var/www/html:rw"
restart: always
ports:
- "80:80"
links:
- "mysql:presta_mysql"

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

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

Installing docker with nginx-proxy I got docker-php-ext-install not found error

I need to install laravel 5 app on Digital Ocean Server (under kubuntu 18) using Docker with VIRTUAL_HOST pointing to my my.freenom.com
host using proxy server (https://github.com/jwilder/nginx-proxy) and for this in my app I use configuraion
docker-compose.yml:
version: '3.1'
services:
web:
image: jwilder/nginx-proxy
build:
context: ./web
dockerfile: Dockerfile.yml
environment:
- APACHE_RUN_USER =#1000
- VIRTUAL_HOST =my.freenom.com
volumes:
- ./mysite.template:/etc/nginx/conf.d/mysite.template
ports:
- 8085:80
working_dir: ${APP_PTH_CONTAINER}
db:
image: mysql:5.5.62
restart: always
environment:
MYSQL_ROOT_PASSWORD: 1
volumes:
- ${DB_PATH_HOST}:/var/lib/mysql
adminer:
image: adminer
restart: always
ports:
- 8086:80
links:
- db
composer:
image: composer:1.6
volumes:
- ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
working_dir: ${APP_PTH_CONTAINER}
command: composer install --ignore-platform-reqs
and in web/Dockerfile.yml :
FROM nginx:1.10
RUN apt-get update -y && apt-get install -y libpng-dev \
nano libmcrypt-dev
RUN docker-php-ext-install \
pdo_mysql \
mcrypt \
&& a2enmod \
rewrite
but running command :
docker-compose up -d --build
I got error :
docker-php-ext-install: not found
Why error and which is correct way?
Thanks!

Resources