github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/docs/content/users/usage/architecture.md (about)

     1  # How DDEV Works
     2  
     3  DDEV is a [Go](https://go.dev) application that stores its configuration in [files on your workstation](#directory-tour).  
     4  It uses those blueprints to mount your project files into [Docker containers](#container-architecture) that facilitate the operation of a local development environment.
     5  
     6  DDEV writes and uses [docker-compose](https://docs.docker.com/compose/) files for you, which is a detail you can cheerfully ignore unless you’re Docker-curious or [defining your own services](../extend/custom-compose-files.md).
     7  
     8  ## Directory Tour
     9  
    10  DDEV stores configuration in two places: a single `.ddev` directory in your home folder, and a `.ddev` directory for each project you set up.
    11  
    12  The [global configuration directory](#global-files) is used to keep track of your projects and any of the [global settings](../configuration/config.md) that apply across all projects. You’ll probably spend more time working with the [per-project `.ddev` directories](#project-files) for their configuration and overrides.
    13  
    14  ### Project Files
    15  
    16  A project’s `.ddev` directory can be intimidating at first, so let’s take a look at what lives in there.
    17  
    18  !!!tip "Yours May Differ Slightly"
    19      You may have some directories or files that aren’t listed here, likely added by custom services.  
    20      For example, if you see a `solr` directory, it probably pertains to a custom Solr [add-on service](../extend/additional-services.md).
    21  
    22  `apache` directory
    23  : Default Apache configuration when using `webserver_type: apache-fpm`, which [can be customized](../extend/customization-extendibility.md#providing-custom-apache-configuration).
    24  
    25  `commands` subdirectories
    26  : Project custom [shell commands](../extend/custom-commands.md) that can run on the host or inside a container.
    27  
    28  `config.yaml`
    29  : The project’s main [configuration file](../configuration/config.md).
    30  
    31  `config.*.yaml` files
    32  : [Environmental overrides](../configuration/config.md#environmental-overrides) for parts of `config.yaml`.
    33  
    34  `db-build` directory
    35  : Can be used to provide a [custom Dockerfile](../extend/customizing-images.md) for the database container.
    36  
    37  `db_snapshots` directory
    38  : Where snapshots go when you run the [`ddev snapshot`](../usage/commands.md#snapshot) command. You can safely delete anything in here that you don’t need.
    39  
    40  `docker-compose.*.yaml` files
    41  : Where Docker-friendly users can provide their own [custom compose files](../extend/custom-compose-files.md) that add or override services. Read more in [Additional Service Configurations & Add-ons](../extend/additional-services.md) and check out examples in [ddev-contrib](https://github.com/drud/ddev-contrib).
    42  
    43  `homeadditions` directory
    44  : Files to be copied into the web container on startup. You could use this, for example, to override the default home directory contents (`.profile`, `.bashrc`, `.composer`, `.ssh`), or include scripts that you’d like to be available inside the container. (You can do the same thing globally in `~/.ddev/homeadditions`.) Check out the [homeadditions docs](../extend/in-container-configuration.md) for more.
    45  
    46  `mutagen` directory
    47  : Contains `mutagen/mutagen.yml`, where you can [override the default Mutagen configuration](../install/performance.md#advanced-mutagen-configuration-options).
    48  
    49  `mysql` directory
    50  : Contains [optional `mysql` or `mariadb` configuration](../extend/customization-extendibility.md#providing-custom-mysqlmariadb-configuration-mycnf).
    51  
    52  `nginx` directory
    53  : Can be used for add-on [nginx snippets](../extend/customization-extendibility.md#custom-nginx-configuration).
    54  
    55  `nginx_full` directory
    56  : Contains the nginx configuration used by the web container, which [can be customized](../extend/customization-extendibility.md#providing-custom-nginx-configuration).
    57  
    58  `postgres` directory
    59  : Contains `postgres/postgresql.conf`, which can be edited if needed. Remove the `#ddev-generated` line at the top to take it over.
    60  
    61  `providers` directory
    62  : Contains examples and implementations to demonstrate how the [`ddev pull`](../usage/commands.md#pull) command can work with [hosting providers](../providers/index.md).
    63  
    64  `traefik` directory
    65  : Configures the `ddev-router` when it is using [Traefik](../configuration/experimental.md#traefik-router).
    66  
    67  `web-build` directory
    68  : Can be used to provide a [custom Dockerfile](../extend/customizing-images.md) for the web container.
    69  
    70  `web-entrypoint.d` directory
    71  : Custom scripts (named `*.sh`) in this directory will be run during web container startup, before the php-fpm server or other daemons are run. This can be useful, for example, for introducing environment variables into the context of the nginx and php-fpm servers. Use this carefully, because custom entrypoints can very easily break things.
    72  
    73  `xhprof` directory
    74  : Contains the `xhprof_prepend.php` file that can be used to customize [xhprof](../debugging-profiling/xhprof-profiling.md) behavior for different types of websites.
    75  
    76  #### Hidden Project Files
    77  
    78  Files beginning with `.` are hidden because they shouldn’t be fiddled with; most are regenerated, and thus overwritten, on every `ddev start`:
    79  
    80  `.dbimageBuild` directory
    81  : The generated Dockerfile used to customize the `db` container on first start.
    82  
    83  `.ddev-docker-compose-base.yaml`
    84  : The base docker-compose file used to describe a project.
    85  
    86  `.ddev-docker-compose-full.yaml`
    87  : The result of preprocessing `.ddev-docker-compose-base.yaml` using `docker-compose config`. Mostly it replaces environment variables with their values.
    88  
    89  `.gitignore`
    90  : The `.gitignore` is generated by DDEV and should generally not be edited or checked in. (It gitignores itself to make sure you don’t check it in.) It’s generated on every `ddev start` and will change as DDEV versions change, so if you check it in by accident it will always be showing changes that you don’t need to see in `git status`.
    91  
    92  `.global_commands`
    93  : Temporary directory used to get global commands available inside a project. You shouldn’t ever have to look there.
    94  
    95  `.homeadditions`
    96  : Temporary directory used to consolidate global `homeadditions` with project-level `homeadditions`. You shouldn’t ever have to look here.
    97  
    98  `.webimageBuild` directory
    99  : The generated Dockerfile used to customize the web container on first start.
   100  
   101  ### Global Files
   102  
   103  There’s only one global `.ddev` directory, which lives in your home directory: `~/.ddev` (`$HOME/.ddev`).
   104  
   105  `global_config.yaml`
   106  : This YAML file defines your global configuration, which consists of various [config settings](../configuration/config.md) along with an important `project_info` key that lets DDEV keep track of the projects you’ve added.
   107  
   108  `bin` directory
   109  : This is where DDEV stores private executable binaries it needs, like `mutagen` and `docker-compose`.
   110  
   111  `commands` directory
   112  : Directory for storing DDEV commands that should be available in containers, like `npm`, `artisan`, and `drush` for example. These are organized in subdirectories named for where they’ll be used: `db`, `host`, and `web`. You can add your own [custom commands](../extend/custom-commands.md) here.
   113  
   114  `homeadditions` directory
   115  : Just like the per-project `homeadditions` directory, files you add here will automatically be copied into the web container’s home directory. Files from the _global_ homeadditions directory will be copied into **every** web container’s home directory.
   116  
   117  #### Hidden Global Files
   118  
   119  Again, these files are mostly regenerated on every `ddev start` so it’s best to leave them alone:
   120  
   121  `.gitignore`
   122  : Prevents files from getting checked in when they shouldn’t be.
   123  
   124  `.router-compose-full.yaml`
   125  : The complete, generated docker-compose directive used for DDEV’s router.
   126  
   127  `.router-compose.yaml`
   128  : The base docker-compose directive used in generating `.router-compose-full.yaml`.
   129  `router-compose.*.yaml`
   130  : `docker-compose` files with the name `router-compose.*.yaml` can be used to override stanzas in the `.router-compose.yaml` file.
   131  
   132  `.ssh-auth-compose-full.yaml`
   133  : The complete, generated docker-compose directive used for DDEV’s SSH agent.
   134  
   135  `.ssh-auth-compose.yaml`
   136  : The base docker-compose directive used in generating `.ssh-auth-compose-full.yaml`.
   137  
   138  `.sshimageBuild`
   139  : Directory used for storing DDEV’s generated `Dockerfile` used in building the SSH agent image.
   140  
   141  `.update`
   142  : An empty file whose purpose is mysterious and intriguing.
   143  
   144  !!!tip "`.ddev_mutagen_data_directory`"
   145      DDEV uses a global `~/.ddev_mutagen_data_directory` for storing [Mutagen](../install/performance.md#mutagen) sync data.
   146  
   147  ## Container Architecture
   148  
   149  It’s easiest to think of DDEV as a set of little networked computers (Docker containers) that are in a different network from your workstation but still reachable from it.
   150  
   151  When you install or upgrade DDEV you’re mostly installing a single `ddev` binary. When you use it, it downloads the Docker images it needs, and then starts them based on what’s needed for your projects.
   152  
   153  * The `ddev-webserver` container (one per project) runs `nginx` or `apache` and `php-fpm` for a single site, so it does all the basic work of a PHP-interpreting web server.
   154  * The `ddev-dbserver` container (one per project) handles MariaDB/MySQL/PostgreSQL database management. It can be reached from the web server by the hostname `db` or with the more explicit name `ddev-<projectname>-db`.
   155  * The optional `dba` container runs phpMyAdmin for projects with MySQL or MariaDB.
   156  * Additional add-on services may be there for a given project, for example `solr` or `elasticsearch` or `memcached`.
   157  
   158  Although it’s not common usage, different projects can communicate with each other as described in the [FAQ](faq.md#can-different-projects-communicate-with-each-other).
   159  
   160  Now for the two oddball global containers (there’s only one of each):
   161  
   162  * The `ddev-router` container is a “reverse proxy”. It takes incoming HTTP/S requests, looks up the hostname in the incoming URL, and routes it to the correct project’s `ddev-webserver`. Depending on the project’s configuration with [`additional_hostnames`](../configuration/config.md#additional_hostnames) and [`additional_fqdns`](../configuration/config.md#additional_fqdns), it can route many different URLs to a single project’s `ddev-webserver`. If, like most people, you use the named URLs like `https://something.ddev.site`, your request goes through the router. When you use the `127.0.0.1` URLs, the requests go directly to the `ddev-webserver`.
   163  * The `ddev-ssh-agent` container runs an `ssh-agent` inside the Docker network so that after run [`ddev auth ssh`](../usage/commands.md#auth-ssh) all the different projects can use your SSH keys for outgoing requests—like private Composer access or SCP from a remote host.
   164  
   165  Here’s a basic diagram of how it works inside the Docker network:
   166  
   167  ![DDEV Docker Network Architecture](../../images/container-diagram.png)