improve initial config

This commit is contained in:
Tchama 2021-02-18 17:46:47 +01:00
parent a628c110a9
commit 00d6a6efbd
3 changed files with 101 additions and 38 deletions

View File

@ -28,9 +28,10 @@ Once you're done, simply `cd` to your project and run `docker-compose up -d`. Th
* Kill containers: `docker-compose kill` * Kill containers: `docker-compose kill`
* View container logs: `docker-compose logs` * View container logs: `docker-compose logs`
* Execute command inside of container: `docker-compose exec SERVICE_NAME COMMAND` where `COMMAND` is whatever you want to run. Examples: * Execute command inside of container: `docker-compose exec SERVICE_NAME COMMAND` where `COMMAND` is whatever you want to run. Examples:
* Shell into the PHP container, `docker-compose exec php bash` * Shell into the PHP container, `docker-compose exec --user 1000 php bash`
* Run symfony console, `docker-compose exec php bin/console` * Run symfony console, `docker-compose exec --user 1000 php bin/console`
* Open a postgresql shell, `docker-compose exec db psql --user admin postgres` * Open a postgresql shell, `docker-compose exec --user postgres db psql`
* or if user is not postgres: `docker-compose exec db psql --user admin postgres`
# Docker general cheatsheet # Docker general cheatsheet
@ -44,27 +45,43 @@ Once you're done, simply `cd` to your project and run `docker-compose up -d`. Th
Disclaimer: This project has been generated on phpdocker.io Disclaimer: This project has been generated on phpdocker.io
# Installation # My installation
* `docker-compose up -d` * Build containers: `docker-compose build`
* in php container `docker-compose exec php bash` * Run containers: `docker-compose up -d`
* `composer create-project symfony/skeleton symfony` * Enter in php container `docker-compose exec --user 1000 php bash`
* `mv symfony/* .` * Install Symfony: `composer create-project symfony/skeleton symfony`
* `mv symfony/.* .` * Move project in parent (app): `mv symfony/* . && mv symfony/.* . && rm -Rf symfony`
* `rm -Rf symfony` * Add Symfony requirements:
* `composer require annotations` ```
* `composer require --dev profiler` composer require annotations
* `composer require twig` composer require --dev profiler
* `composer require orm` composer require twig
* `composer require form` composer require orm
* `composer require form validator` composer require form
* `composer require maker-bundle` composer require form validator
* `docker-compose down` composer require maker-bundle
* adapt querystring in `./app/.env`: composer require security-csrf
```
* Stop containers: `docker-compose down`
* Adapt querystring in `./app/.env`:
``` ```
--- DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8" --- DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"
+++ DATABASE_URL="postgresql://admin:secret@db:5432/postgres?serverVersion=12&charset=utf8" +++ DATABASE_URL="postgresql://postgres:secret@db:5432/postgres?serverVersion=12&charset=utf8"
``` ```
* `docker-compose up -d` * Run containers: `docker-compose up -d`
* in php container `docker-compose exec php bash` * Enter in php container `docker-compose exec --user 1000 php bash`
* `bin/console doctrine:schema:create` * Test psql connection: `psql --host db --user postgres --password postgres`
* Create database schema: `bin/console doctrine:schema:create`
## Let's go !
* Let's create first object:
* Create entity: `bin/console make:entity Beer`
* Create CRUD on entity: `bin/console make:crud Beer`
* See sql: `bin/console doctrine:schema:update --dump-sql`
* Control migrations: `bin/console doctrine:migrations:status`
* Generate migration file: `bin/console doctrine:migrations:diff`
* See migration file: `cat migrations/Version20210218160541.php `
* Migrate: `bin/console doctrine:migrations:migrate`
* Control migrations: `bin/console doctrine:migrations:status`

View File

@ -3,12 +3,12 @@ services:
db: db:
image: postgres:12 image: postgres:12
container_name: docker-sf5-postgres
volumes: volumes:
#- ./data:/var/lib/postgresql/data # comment to keep data in docker volumes
- ./data:/var/lib/postgresql/data
- ./docker_build/db/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d - ./docker_build/db/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
environment: environment:
- "POSTGRES_USER=admin" - "POSTGRES_USER=postgres"
- "POSTGRES_PASSWORD=secret" - "POSTGRES_PASSWORD=secret"
- "POSTGRES_DB=postgres" - "POSTGRES_DB=postgres"
ports: ports:
@ -16,7 +16,6 @@ services:
nginx: nginx:
image: nginx:latest image: nginx:latest
container_name: docker-sf5-nginx
working_dir: /var/www/app working_dir: /var/www/app
volumes: volumes:
- ./app:/var/www/app - ./app:/var/www/app
@ -29,7 +28,6 @@ services:
context: ./docker_build/php context: ./docker_build/php
args: args:
UID: 1000 UID: 1000
container_name: docker-sf5-php
image: php-fpm_sf5:latest image: php-fpm_sf5:latest
working_dir: /var/www/app working_dir: /var/www/app
volumes: volumes:

View File

@ -1,12 +1,60 @@
FROM phpdockerio/php72-fpm:latest FROM php:7.3-fpm-buster
# Set the lifetime of a PHP session
ARG SESSION_LIFETIME=10800
# Set default UID for the PHP user
ARG UID=1000
ARG GID=1000
# Install postgresql client
# and compile docker php extensions
RUN apt update \
&& apt -y --no-install-recommends install \
wget \
gnupg \
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& apt update \
&& apt -y --no-install-recommends install \
libicu-dev \
g++ \
libzip-dev \
libzip4 \
unzip \
libfreetype6-dev \
libpng-dev \
libjpeg62-turbo-dev \
libpq5 \
libpq-dev \
postgresql-12 \
git \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install intl pdo_pgsql mbstring zip bcmath sockets exif \
&& apt remove -y \
wget \
gnupg \
libicu-dev \
g++ \
libzip-dev \
libpq-dev \
&& apt autoremove -y \
&& apt purge -y
# Set php timezone
RUN { \
echo ""; \
echo "[Date]"; \
echo "date.timezone = Europe/Brussels"; \
echo ""; \
} >> /usr/local/etc/php/conf.d/date.ini
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR "/var/www/app" WORKDIR "/var/www/app"
# Install selected extensions and other stuff # Add users/groups with uid 1000
RUN apt-get update \ RUN groupadd --gid ${GID} "group${GID}" \
&& apt-get -y --no-install-recommends install php7.2-mysql \ && useradd --uid ${UID} --gid ${GID} --create-home "user${UID}"
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install git
RUN apt-get update \
&& apt-get -y install git \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*