Skip to content
Michael Härtl edited this page Feb 24, 2016 · 7 revisions

How can I run Yii console commands?

docker-compose run --rm web yii migrate
docker-compose run --rm web yii mycommand/myaction

Where are composer packages installed?

Composer packages are installed inside the container under /var/www/vendor. So they live outside of the app directory. This is because during development we usually mount the local app directory into the /var/www/html directory of the container. This would override any vendor packages we have there. So you would either have to locally install all the packages in vendor/ or somehow make sure, that the composer packages are updated after the local dir was shared.

By keeping the directory outside, we circumvent this issue. The docker images will always contain all required composer dependencies and use those at runtime.

How can I update or install new composer packages?

To update or install new packages you first need an updated local composer.lock file. Then the next time you issue docker-compose build it will pick up the changed file and create a new docker image with the updated packages inside:

docker-compose run --rm web composer update my/package
docker-compose build

Note: If you face the nasty API rate limit issue with github, you can create a personal API token and expose it in your docker-compose.yml file as API_TOKEN env var.

How can I make composer packages available locally?

Some IDE's may require a copy of the vendor directory somewhere on your local host for autocompleting commands or providing inline help. You can therefore copy the vendor directory to your local directory:

docker-compose run --rm web cp -r /var/www/vendor .

How can I log the container output to a file?

The default log configuration follows the Docker convention to log to STDOUT and STDERR. If you want a logfile for your containers you can add this configuration to the docker-compose.yml:

    log_driver: "syslog"
    log_opt:
        tag: "docker-web"

If you're on Debian and use Rsyslog for logging put the following into a new file in /etc/rsyslog.d/30-docker.conf:

# Log docker messages to one file per container
$template DockerFileName,"/var/log/docker/%syslogtag:R,ERE,1,DFLT:docker/(.*)\[--end%.log"

# Log messages usually already contain a timestamp, so only log the raw message
$template DockerLog,"%msg%\n"
:syslogtag,startswith,"docker/" ?DockerFileName;DockerLog

# Do not pollute default syslog with docker messages
& ~
$ sudo mkdir /var/log/docker
$ sudo chown syslog /var/log/docker

This will create one logfile per container in /var/log/docker/ with the logtag suffixed by .log as filename. You may also want to create a logrotate config in /etc/logrotate.d/docker-container:

/var/log/docker/*.log
{
    rotate 7
    daily
    missingok
    notifempty
    delaycompress
    compress
    postrotate
        reload rsyslog >/dev/null 2>&1 || true
    endscript
}

How can I use Yii's log routes?

If you log to the default directory, you should find the logfiles in your local runtime/logs/ directory. Note, that this directory will never be copied into the container, so there's no risk, that you end up with a bloated image.

How Can I Add PHP / HHVM Extensions?

Since the codemix/yii2-base image extends from the official php image, you can use docker-php-ext-install in your Dockerfile. Here's an example:

RUN apt-get update \
    && apt-get -y install \
            libfreetype6-dev \
            libjpeg62-turbo-dev \
            libmcrypt-dev \
            libpng12-dev \
        --no-install-recommends \
    && rm -r /var/lib/apt/lists/* \
    && docker-php-ext-install iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install gd

For HHVM extension please check the hhvm base image for details.

Clone this wiki locally