-
Notifications
You must be signed in to change notification settings - Fork 51
2. How to use
To use this image you'll follow these two steps:
- Create a new project
- Set up and configure your development environment
We'll cover both steps in more detail below.
As mentioned above, this project is a template for your own projects. So when creating a new project you basically will
- copy the code into some directory,
- modify the main app configuration, usable environment variables, composer dependencies, README.md, inital DB migration, etc.
- commit the above to your repository
To copy the code to your computer, you can use composer to do the main work for you:
composer create-project --no-install codemix/yii2-dockerized myproject
As for step 2 above, you may first want to select a flavour of the docker base. You only need to uncomment the appropriate line in the Dockerfile
:
FROM codemix/yii2-base:2.0.9-php7-apache
#FROM codemix/yii2-base:2.0.9-php7-fpm
#FROM codemix/yii2-base:2.0.9-hhvm
Then you should check the following files and directories:
-
Dockerfile
: Optionally add PHP extensions -
docker-compose-example.yml
: Provide an example machine configuration for other developers -
config/web.php
/config/console.php
: Update the main configuration -
.env-example
: Add more environment variables -
composer.json
: Add more dependencies for your project -
migrations/
: Update the initial DB migration to match your DB model -
README.md
: Describe your application
If you think everything is fine, it's time for the first commit to your project's repository. This will now be the starting point for your developers.
When you have the project in your repository, it's easy to set up a new development environment, e.g. for a new team member:
git clone <your-repo-url> ./myapp
cd myapp
cp docker-compose-example.yml docker-compose.yml
cp .env-example .env
docker-compose up
# From another terminal window:
docker-compose run --rm web ./yii migrate
It may take some minutes to download the required docker images. When done, you can access the new app from http://localhost:8080.
Note: The local app directory will be mapped into the
/var/www/html
directory of theweb
container. So you can always work on your local source files and will immediately see the results under the URL of the container.
The next step is to configure the application. For example you will want to enable YII_DEBUG
or set other local configurations during development. So read on in the next section.