Search code examples
phpwordpressdockeramazon-ecs

wp-config.php already exists for WordPress (Docker, ECS)


I am running WordPress inside a container and hosting it on ECS. The database is RDS.

Everytime I build a new docker container and deploy to ECS it requires a fresh install. Then it says wp-config.php already exists.

I am tempted to copy the wp-config.php populated with the database configuration into the container but that is not a good practice.

How can I solve this?


Solution

  • Well, it's definitely not best practice to do the configuration manually over and over again, either ;)

    To have persistent data with docker, you can either use volumes or bind mounts. In both cases the data is directly stored on the backing file system, not using the overlay / union file system, that is used for containers.

    Volumes are handled by the docker engine, bind mounts are directly mapped to where you specified. If you are using docker compose, your docker-compose.yml would look like

    version: "3.5"
    services:
      your_service:
      image: your_image
      volumes:
       # bind mount example
       - type: bind
         source: /path/on/host
         target: /path/inside/container
       # volume example
       - type: volume
         source: your_volume
         target: /path/inside/container
     [...]
     volumes:
       your-volume:
    

    The equivalent commands for docker run can be found on docs.docker.com . For example

    docker run --volume=[host-src:]container-dest[:<options>] ...