Wordpress on docker-compose no run

前端 未结 6 1736
遇见更好的自我
遇见更好的自我 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:24

    As said earlier you should add

    depends_on:
      - db
    

    but after this I still getting message about connection problem. And only this clear problem - second option:

    networks:
        local:
    

    This solve error PHP Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in Standard input code on line 22

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-02 05:25

    I did not use yml, but had same logs and this did not work

    docker run -dP --link elated_yonath -e WORDPRESS_DB_USER=libik -e WORDPRESS_DB_PASSWORD=prdik wordpress 
    

    But then I found, that I have to add :mysql to linked container

    docker run -dP --link elated_yonath:mysql -e WORDPRESS_DB_USER=libik -e WORDPRESS_DB_PASSWORD=prdik wordpress 
    

    Now it started.

    0 讨论(0)
  • 2021-01-02 05:38

    Adding these under 'db:' solved it for me.

        command: --default-authentication-plugin=mysql_native_password
        restart: always
    
    0 讨论(0)
  • 2021-01-02 05:40

    This anwser works for me, cause I didn't have enough reputation to vote that anwser, I copy it here:

    depends_on:
      - db
    

    That just makes sure the database container is fully loaded before the wordpress container. You need to tell docker to link the db container from the wordpress container to reference it by name.

    What docker-compose does under the hood is take the ip docker gives the dbcontainer and add a /etc/hosts entry to the wordpress container so you can reference it by name.

    So try adding this to the wordpress section

    links:
      - db
    
    0 讨论(0)
  • 2021-01-02 05:45

    Solution:

    Remember to link the mysql container to the wordpress container:

    links:
       - db:mysql
    

    Like this:

    version: '2'
    services:
      wordpress:
        image: wordpress
        ports:
          - "8080:80"
        links:
          - db:mysql
        environment:
          WORDPRESS_DB_PASSWORD: example
      db:
        image: mysql:5.7
        environment:
          MYSQL_ROOT_PASSWORD: example
    

    This important detail is not mentioned on the WordPress image official Dockerhub page

    0 讨论(0)
提交回复
热议问题