From fa751a34e4fcc40bdea09812f17db36cf977f388 Mon Sep 17 00:00:00 2001 From: Tobias Munk Date: Tue, 15 Jan 2019 18:37:04 +0100 Subject: [PATCH] Added minimal Docker setup (#347) --- backend/Dockerfile | 4 ++++ docker-compose.yml | 38 ++++++++++++++++++++++++++++++++ docs/guide/start-installation.md | 38 ++++++++++++++++++++++++++++++++ frontend/Dockerfile | 4 ++++ 4 files changed, 84 insertions(+) create mode 100644 backend/Dockerfile create mode 100644 docker-compose.yml create mode 100644 frontend/Dockerfile diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..380c0cd --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,4 @@ +FROM yiisoftware/yii2-php:7.2-apache + +# Create a symlink for apache (if `/var/www/html` is available) +RUN rm -rf /var/www/html && ln -s /app/backend/web/ /var/www/html || true \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c8ad750 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3.2' + +services: + + frontend: + build: frontend + ports: + - 20080:80 + volumes: + # Re-use local composer cache via host-volume + - ~/.composer-docker/cache:/root/.composer/cache:delegated + # Mount source-code for development + - ./:/app + + backend: + build: backend + ports: + - 21080:80 + volumes: + # Re-use local composer cache via host-volume + - ~/.composer-docker/cache:/root/.composer/cache:delegated + # Mount source-code for development + - ./:/app + + mysql: + image: mysql:5.7 + environment: + - MYSQL_ROOT_PASSWORD=verysecret + - MYSQL_DATABASE=yii2advanced + - MYSQL_USER=yii2advanced + - MYSQL_PASSWORD=secret + + #pgsql: + # image: postgres:9.5 + # environment: + # - POSTGRES_DB=yii2advanced + # - POSTGRES_USER=yii2advanced + # - POSTGRES_PASSWORD=secret \ No newline at end of file diff --git a/docs/guide/start-installation.md b/docs/guide/start-installation.md index 07b5de9..a664aad 100644 --- a/docs/guide/start-installation.md +++ b/docs/guide/start-installation.md @@ -280,3 +280,41 @@ That's all. You just need to wait for completion! After that you can access proj * frontend: http://y2aa-frontend.test * backend: http://y2aa-backend.test + +### Installing using Docker + +Install the application dependencies + + docker-compose run --rm backend composer install + +Initialize the application by running the `init` command within a container + + docker-compose run --rm backend /app/init + +Add a database service like and adjust the components['db'] configuration in `common/config/main-local.php` accordingly. + + 'dsn' => 'mysql:host=mysql;dbname=yii2advanced', + 'username' => 'yii2advanced', + 'password' => 'secret', + +> Docker networking creates a DNS entry for the host `mysql` available from your `backend` and `frontend` containers. + +> If you want to use another database, such a Postgres, uncomment the corresponding section in `docker-compose.yml` and update your database connection. + +> 'dsn' => 'pgsql:host=pgsql;dbname=yii2advanced', + +For more information about Docker setup please visit the [guide](http://www.yiiframework.com/doc-2.0/guide-index.html). + +Run the migrations + + docker-compose run --rm backend yii migrate + +Start the application + + docker-compose up -d + +Access it in your brower by opening + +- frontend: http://127.0.0.1:20080 +- backend: http://127.0.0.1:21080 + diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..cf187a3 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,4 @@ +FROM yiisoftware/yii2-php:7.2-apache + +# Create a symlink for apache (if `/var/www/html` is available) +RUN rm -rf /var/www/html && ln -s /app/frontend/web/ /var/www/html || true \ No newline at end of file