Skip to content

Instantly share code, notes, and snippets.

@mikehaertl
Last active September 19, 2022 21:20
Show Gist options
  • Save mikehaertl/0a4a83e8ee82ce835384 to your computer and use it in GitHub Desktop.
Save mikehaertl/0a4a83e8ee82ce835384 to your computer and use it in GitHub Desktop.

Revisions

  1. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 8 additions and 7 deletions.
    15 changes: 8 additions & 7 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -15,29 +15,30 @@ The image is not a static, though. In fact, it will see many revisions over time

    To build both, the initial image and a new revision, we use a [Dockerfile](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile). This file basically contains a recipe for how to build your image from scratch.

    Since with docker you use one container for each process we will use [fig](http://www.fig.sh/) to help us manage the different containers. So you may have a `web` and a `db` container. `fig` also helps us to map your local app code into the container, so that you can modify it on the fly during development.
    Since with docker you use one container for each process we will use [fig](http://www.fig.sh/) to help us manage the different containers. So you may have a `web` and a `db` container. `fig` also helps us to map your local app code into the container, so that you can modify it on the fly during development. And `fig` even builds a new image for us, whenever we want.

    So let's look at the different project phases in a bit more detail:

    ### 1. Initialize your project
    #### 1. Initialize the project

    * Prepare your initial project files in a directory (e.g. `app/`)
    * Prepare our initial project files in a directory (e.g. `app/`)
    * Create an initial Dockerfile that also `COPY`s the above directory into the image
    * Create a fig.yml file to describe your server setup (e.g. web, db, ...)
    * Create a fig.yml file to describe our server setup (e.g. web, db, ...)
    * Issue a `fig build web` to let docker build the initial project image

    You can now distribute what you created so far:
    We can now distribute what we 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?)

    ### 2. Use it in development
    #### 2. Develop

    * Clone your project repository
    * Run `fig up` to 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.

    ### 3. Prepare a release
    #### 3. Prepare a release

    * When you're ready for a release, run `fig build web` again, 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
  2. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -4,14 +4,14 @@ These ideas are **WORK IN PROGRESS**!

    ### Summary

    We want to create a self contained docker image for your application. This means, that the image will not only contain your code, but also all the dependencies that are neccessary to run your code. This image can then be used for both, easy deployment in production and as basis for ongoing development.
    The core idea with this workflow is that we end up with a self contained docker image of your application. This image will not only contain our code, but also all the dependencies that are neccessary to run the code. This image can then be used for both, easy deployment in production and as basis for ongoing development.

    In fact, the image will see many revisions over time - which is supported nicely through dockers inheritance approach. You basically
    The image is not a static, though. In fact, it will see many revisions over time - which is supported nicely through dockers inheritance approach. We basically

    1. start with an image and put all your initial code and dependencies in there,
    2. then you develop new features
    3. and finally commit changes into a new image revision whenever you feel ready.
    4. Go back to 2.
    1. start with an image and put all our initial code and dependencies in there,
    2. then develop new features
    3. and finally commit changes into a new image revision whenever we feel ready for another release.
    4. We finally loop back to 2.

    To build both, the initial image and a new revision, we use a [Dockerfile](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile). This file basically contains a recipe for how to build your image from scratch.

  3. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,9 @@ In fact, the image will see many revisions over time - which is supported nicely
    3. and finally commit changes into a new image revision whenever you feel ready.
    4. Go back to 2.

    To build both, the initial image and a new revision, we use a [Dockerfile](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile). This basically describes, how to build the image from scratch.
    To build both, the initial image and a new revision, we use a [Dockerfile](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile). This file basically contains a recipe for how to build your image from scratch.

    Since with docker you use one container for each process we will use [fig](http://www.fig.sh/) to help us manage the different containers. So you may have a `web` and a `db` container. `fig` also helps us to map your local app code into the container, so that you can modify it on the fly during development.


    ### 1. Initialize your project
  4. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -8,9 +8,9 @@ We want to create a self contained docker image for your application. This means

    In fact, the image will see many revisions over time - which is supported nicely through dockers inheritance approach. You basically

    1. start with an image and put all your initial code and dependencies in there. Then you
    2. develop new features and then
    3. commit changes into a new image revision whenever you feel ready.
    1. start with an image and put all your initial code and dependencies in there,
    2. then you develop new features
    3. and finally commit changes into a new image revision whenever you feel ready.
    4. Go back to 2.

    To build both, the initial image and a new revision, we use a [Dockerfile](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile). This basically describes, how to build the image from scratch.
  5. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,20 @@

    These ideas are **WORK IN PROGRESS**!

    ### Summary

    We want to create a self contained docker image for your application. This means, that the image will not only contain your code, but also all the dependencies that are neccessary to run your code. This image can then be used for both, easy deployment in production and as basis for ongoing development.

    In fact, the image will see many revisions over time - which is supported nicely through dockers inheritance approach. You basically

    1. start with an image and put all your initial code and dependencies in there. Then you
    2. develop new features and then
    3. commit changes into a new image revision whenever you feel ready.
    4. Go back to 2.

    To build both, the initial image and a new revision, we use a [Dockerfile](https://docs.docker.com/userguide/dockerimages/#building-an-image-from-a-dockerfile). This basically describes, how to build the image from scratch.


    ### 1. Initialize your project

    * Prepare your initial project files in a directory (e.g. `app/`)
  6. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -80,7 +80,7 @@ db:
    MYSQL_PASSWORD: secret
    MYSQL_DATABASE: yii
    ```
    * Run `fig up` to start your setup. You should be able to access http://localhost:8000 (you may have to replace `localhost` with the IP of your VM if you're on Win/OsX).
    * Run `fig up` to start your setup. You should be able to access [http://localhost:8000](http://localhost:8000) (you may have to replace `localhost` with the IP of your VM if you're on Win/OsX).

    ## Best practices

  7. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -80,7 +80,7 @@ db:
    MYSQL_PASSWORD: secret
    MYSQL_DATABASE: yii
    ```
    * Run `fig up` to start your setup
    * Run `fig up` to start your setup. You should be able to access http://localhost:8000 (you may have to replace `localhost` with the IP of your VM if you're on Win/OsX).

    ## Best practices

  8. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -89,7 +89,7 @@ db:
    * 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](https://docs.docker.com/userguide/dockerlinks/#environment-variables) by docker. You can pass more into the container through your `fig.yml`. In your PHP application you can also use [phpdotenv](https://github.com/vlucas/phpdotenv) to use a `.env` file for configuration.

    ## Tipps
    ## Tips

    * To install a composer package you fire a one-off command:
    ```
  9. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,8 @@ These ideas are **WORK IN PROGRESS**!

    ### 1. Initialize your project

    * Prepare your initial project files in a directory (e.g. app/)
    * Create an initial Dockerfile that includes the above directory
    * Prepare your initial project files in a directory (e.g. `app/`)
    * Create an initial Dockerfile that also `COPY`s the above directory into the image
    * Create a fig.yml file to describe your server setup (e.g. web, db, ...)
    * Issue a `fig build web` to let docker build the initial project image

  10. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -95,8 +95,7 @@ db:
    ```
    fig run web composer require some/package
    ```

    ## Open questions
    * How to provision the DB (`yii migrate`)?
    * How to persist the DB data?

    * To run yii migrations, open fire up the container (`fig up`) then from a second terminal window do
    ```
    fig run web /app/yii migrate --interactive=0
    ```
  11. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -80,6 +80,7 @@ db:
    MYSQL_PASSWORD: secret
    MYSQL_DATABASE: yii
    ```
    * Run `fig up` to start your setup

    ## Best practices

  12. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 27 additions and 3 deletions.
    30 changes: 27 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,15 @@ You can now distribute what you created so far:
    ```
    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 (TODO: Add more details on that here).
    * Modify the configuration to use environment variables e.g. for DB host credentials
    ```[php]
    'db' => [
    'dsn' => 'mysql:host='.getenv('DB_PORT_3306_TCP_ADDR').';dbname=yii',
    'username' => 'app',
    'password' => 'secret',
    ],
    ```
    * Create a `Dockerfile` with a minimal PHP setup
    ```
    FROM debian:wheezy
    @@ -66,12 +74,28 @@ web:
    - db
    db:
    image: mysql
    environment:
    MYSQL_ROOT_PASSWORD: secretroot
    MYSQL_USER: app
    MYSQL_PASSWORD: secret
    MYSQL_DATABASE: yii
    ```

    ## Best practices

    * 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. You can define those in different ways, e.g. in the `fig.yml` or through an `.env` file if you use [phpdotenv](https://github.com/vlucas/phpdotenv).
    * Configure the containers through environment variables. Some environment variables are [automatically provided](https://docs.docker.com/userguide/dockerlinks/#environment-variables) by docker. You can pass more into the container through your `fig.yml`. In your PHP application you can also use [phpdotenv](https://github.com/vlucas/phpdotenv) to use a `.env` file for configuration.

    ## Tipps

    * To install a composer package you fire a one-off command:
    ```
    fig run web composer require some/package
    ```

    ## Open questions
    * How to provision the DB (`yii migrate`)?
    * How to persist the DB data?

  13. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -71,5 +71,7 @@ db:

    ## Best practices

    * 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. You can define those in different ways, e.g. in the `fig.yml` or through an `.env` file if you use [phpdotenv](https://github.com/vlucas/phpdotenv).
  14. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,9 @@ You can now distribute what you created so far:
    ## Example

    * Create a new Yii2 project in an `app/` directory
    `composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic`
    ```
    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 (TODO: Add more details on that here).
    * Create a `Dockerfile` with a minimal PHP setup
    ```
    @@ -65,4 +67,9 @@ web:
    db:
    image: mysql
    ```
    ```

    ## Best practices

    * Build ephemeral containers! You should be able to exchange your container in production without data loss.
    * Configure the containers through environment variables. You can define those in different ways, e.g. in the `fig.yml` or through an `.env` file if you use [phpdotenv](https://github.com/vlucas/phpdotenv).
  15. mikehaertl revised this gist Oct 23, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    These ideas are **WORK IN PROGRESS**!

    ### Initialize your project
    ### 1. Initialize your project

    * Prepare your initial project files in a directory (e.g. app/)
    * Create an initial Dockerfile that includes the above directory
    @@ -14,14 +14,14 @@ 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?)

    ### Use it in development
    ### 2. Use it in development

    * Clone your project repository
    * Run `fig up` to 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.

    ### Prepare a release
    ### 3. Prepare a release

    * When you're ready for a release, run `fig build web` again, 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
  16. mikehaertl revised this gist Oct 23, 2014. 3 changed files with 35 additions and 30 deletions.
    17 changes: 0 additions & 17 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -1,17 +0,0 @@
    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
    37 changes: 35 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -31,5 +31,38 @@ You can now distribute what you created so far:
    * 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 (TODO: Add more details on that here).
    * Create a `Dockerfile` with a minimal PHP setup (see example below)
    * Create a `fig.yml` (see example below)
    * Create a `Dockerfile` with 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`
    ```[YAML]
    web:
    build: .
    command: php -S 0.0.0.0:8000 -t /app/web
    ports:
    - "8000:8000"
    volumes:
    - ./app:/app
    links:
    - db
    db:
    image: mysql
    ```
    11 changes: 0 additions & 11 deletions fig.yml
    Original file line number Diff line number Diff line change
    @@ -1,11 +0,0 @@
    web:
    build: .
    command: php -S 0.0.0.0:8000 -t /app/web
    ports:
    - "8000:8000"
    volumes:
    - ./app:/app
    links:
    - db
    db:
    image: mysql
  17. mikehaertl created this gist Oct 23, 2014.
    17 changes: 17 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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
    35 changes: 35 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    ## Docker Development Workflow

    These ideas are **WORK IN PROGRESS**!

    ### Initialize your project

    * 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 web` to 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?)

    ### Use it in development

    * Clone your project repository
    * Run `fig up` to 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.

    ### Prepare a release

    * When you're ready for a release, run `fig build web` again, 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

    ## Example

    * 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 (TODO: Add more details on that here).
    * Create a `Dockerfile` with a minimal PHP setup (see example below)
    * Create a `fig.yml` (see example below)
    11 changes: 11 additions & 0 deletions fig.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    web:
    build: .
    command: php -S 0.0.0.0:8000 -t /app/web
    ports:
    - "8000:8000"
    volumes:
    - ./app:/app
    links:
    - db
    db:
    image: mysql