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

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"

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...

Memcached >= 2.2.0 is required. Symfony and Docker

Here's what I've tried..
docker-compose.yml
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/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:
- "8235:80"
- "455:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
- ./nginx/ssl:/etc/nginx/ssl
networks:
- app-network
# try this...
memcached:
container_name: memcached
image: memcached:latest
ports:
- "11212:11211"
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
Dockerfile
# ... omitted for brevity
# try this..
RUN apt-get update && apt-get install -y \
memcached
# now try this...
RUN docker-php-ext-install libz-dev libmemcached-dev
RUN docker-php-ext-install pecl install memcached
RUN docker-php-ext-install docker-php-ext-enable memcached
# and this...
RUN docker-php-ext-install build-essential libmemcached-dev libz-dev
RUN pecl install memcached-2.2.0
RUN echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini
The local site is up and serving files (Symfony) only I'm met with the memcached exception:
Any ideas?
Dropping this in my Dockerfile fixed it
RUN apt-get update && apt-get install -y libmemcached-dev \
&& pecl install memcached \
&& docker-php-ext-enable memcached

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

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