These ideas are WORK IN PROGRESS!
- Prepare your initial project files in a directory (e.g. app/)
- Create an initial Dockerfile that includes the above directory
- Create a fig.yml file to describe your server setup (e.g. web, db, ...)
- Issue a
fig build webto let docker build the initial project image
You can now distribute what you created so far:
- Commit all the above including the Dockerfile and fig.yml to your repository
- Push the docker image to a docker repository (TODO: How will this work? And how to reuse that in the fig.yml?)
- Clone your project repository
- Run
fig upto start your environment - The local
app/directory is shared with the running docker container, so you can now develop/modify code there. It will override whatever is stored in the docker image, so that you always can work with the latest code. - When done, you can commit and push your code as usual.
- When you're ready for a release, run
fig build webagain, to update the docker image and push that image. (TODO: How to tag that image with fig?) - Pull this latest image to production and start a container from there
- Create a new Yii2 project in an
app/directory
composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic
- Modify the configuration to use environment variables e.g. for DB host credentials
'db' => [
'dsn' => 'mysql:host='.getenv('DB_PORT_3306_TCP_ADDR').';dbname=yii',
'username' => 'app',
'password' => 'secret',
],
- Create a
Dockerfilewith a minimal PHP setup
FROM debian:wheezy
# Modify the PHP modules below to match your project requirements
RUN apt-get update && \
apt-get install -y \
php5-cli \
php5-imagick \
php5-intl \
php5-mcrypt \
php5-mysql \
php-apc && \
rm -rf /var/lib/apt/lists/*
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin && \
ln -s /usr/local/bin/composer.phar /usr/local/bin/composer
COPY app/ /app
- Create a
fig.yml
web:
build: .
command: php -S 0.0.0.0:8000 -t /app/web
ports:
- "8000:8000"
volumes:
- ./app:/app
links:
- db
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: secretroot
MYSQL_USER: app
MYSQL_PASSWORD: secret
MYSQL_DATABASE: yii
- Run
fig upto start your setup
- Use one container per process
- Make the containers self contained! I.e. include all your app code and app dependencies (No more provisioning on deployment!)
- Build ephemeral containers! You should be able to exchange your container in production without data loss.
- Configure the containers through environment variables. Some environment variables are automatically provided by docker. You can pass more into the container through your
fig.yml. In your PHP application you can also use phpdotenv to use a.envfile for configuration.
- To install a composer package you fire a one-off command:
fig run web composer require some/package
- How to provision the DB (
yii migrate)? - How to persist the DB data?
Good idea, I just want to comment that FIG is now deprecated and replaced with Docker Compose.
I am also looking at otto ( https://ottoproject.io) to achieve this..