Wordpress on docker-compose no run

前端 未结 6 1748
遇见更好的自我
遇见更好的自我 2021-01-02 05:07

This is my docker-compose.yml

version: \'2\'
services:
  wordpress:
    image: wordpress
    ports:
      - \"8080:80\"
    environment:
      WORDPRESS_DB_P         


        
6条回答
  •  遥遥无期
    2021-01-02 05:25

    Are you setting the DB host (and other needed MySql attributes), in your Compose file wordpress service (other than password, shown in your post)? e.g.:

    environment:
      WORDPRESS_DB_PASSWORD: example
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: {xxx}
      WORDPRESS_DB_NAME: {xxx}
      WORDPRESS_TABLE_PREFIX: {xxx}
    

    In particular the "host" value, which in your setup should be db. You should not have to do any linking, although it would be a good idea to add

    depends_on:
      - db
    

    to your wordpress service block which will set the dependency order to start the db container before your wordpress container. (A links attribute would do the same, but trying to keep things simple.)

    Note:

    By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.

    Links allow you to define extra aliases by which a service is reachable from another service. They are not required to enable services to communicate - by default, any service can reach any other service at that service’s name.

    https://docs.docker.com/compose/networking/#/links

    I would not mess around with networks unless you really understand what you are doing, as in most cases the defaults will work fine. If you have some special case, you can always optimize that later.

提交回复
热议问题