title: How to use a wordpress container with a wp-cli container when /var/www/html is already mounted in the host?
body: <p>I tried using networks, but the network with the folder's name concatenated with "_default" is not found.</p>
  
  <p>If I specify the network like this:</p>
  
  <pre><code>  wpcli:
      container_name: ...
      image: wordpress:cli
      working_dir: /var/www/html
      depends_on:
        - db
        - wordpress
      networks:
        - A_default
  </code></pre>
  
  <p>I get:</p>
  
  <blockquote>
    <p><strong>ERROR</strong>: Service "wpcli" uses an undefined network "A_default"</p>
  </blockquote>
  
  <p>although <code>A_default</code> exists in the output of <code>docker network ls</code>.</p>
  
  <p>If I remove the part:</p>
  
  <pre><code>    networks:
        - A_default
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p><strong>wpcli_1</strong>       | Error: This does not seem to be a WordPress installation.</p>
    
    <p><strong>wpcli_1</strong>       | Pass --path=<code>path/to/wordpress</code> or run <code>wp core download</code>.</p>
    
    <p><strong>A_wpcli_1</strong> exited with code 1</p>
  </blockquote>
  
  <p>and only this error in the <code>docker-compose up</code> output.</p>
  
  <p>If I use</p>
  
  <pre><code>    volumes:
        - /var/www/html
  </code></pre>
  
  <p>inside the <code>wpcli</code> section of my <code>docker-compose.yml</code> I get the same error.</p>
  
  <h1><code>docker-compose.yml</code></h1>
  
  <p>Below is my <code>docker-compose.yml</code> with sensible information replaced with <code>...</code>:</p>
  
  <pre><code>version: '3.3'
  
  services:
    db:
      container_name: A_db_1
      image: mysql:5.7
      volumes:
        - db_data:/var/lib/mysql
      restart: "no"
      environment:
        MYSQL_DATABASE: '...'
        MYSQL_USER: '...'
        MYSQL_PASSWORD: '...'
        MYSQL_ROOT_PASSWORD: ...
  
    phpmyadmin:
      container_name: A_phpmyadmin_1
      depends_on:
        - db
      restart: "no"
      ports:
        - "8080:80"
      image: phpmyadmin/phpmyadmin
      environment:
        PMA_HOST: db:3306
        PMA_USER: root
        PMA_PORT: 3306
        PMA_PASSWORD: ...
  
    wordpress:
      container_name: A_wordpress_1
      depends_on:
        - db
      image: wordpress:latest
      ports:
        - "80:80"
      volumes:
        - type: bind
          source: ./html
          target: /var/www/html
          volume:
            nocopy: true
      restart: "no"
      environment:
        WORDPRESS_DB_NAME: '...'
        WORDPRESS_DB_USER: '...'
        WORDPRESS_DB_PASSWORD: '...'
        WORDPRESS_DB_HOST: db:3306
        WORDPRESS_TABLE_PREFIX: 'wp_'
        WORDPRESS_AUTH_KEY: '...'
        WORDPRESS_SECURE_AUTH_KEY: '...'
        WORDPRESS_LOGGED_IN_KEY: '...'
        WORDPRESS_NONCE_KEY: '...'
        WORDPRESS_AUTH_SALT: '...'
        WORDPRESS_SECURE_AUTH_SALT: '...'
        WORDPRESS_LOGGED_IN_SALT: '...'
        WORDPRESS_NONCE_SALT: '...'
  
    wpcli:
      container_name: A_wpcli_1
      image: wordpress:cli
      working_dir: /var/www/html
      depends_on:
        - db
        - wordpress
      networks:
        - A_default
  
  volumes:
    db_data:
  </code></pre>
  
  <p>Thank you.</p>
  
  <h1>Update 1</h1>
  
  <p>I have seen <a href="https://github.com/docker-library/wordpress/blob/c63f536e5d24b474c93e6c4b8deeacf95a89eb64/php7.2/cli/Dockerfile" rel="nofollow noreferrer">this file</a> but I do not find it helpful in my situation.</p>
  
  <h1>Update 2</h1>
  
  <p>I wish to use a separate container just for WP-CLI because the command</p>
  
  <pre class="lang-sh prettyprint-override"><code>docker run -it --rm \
      --volumes-from A_wordpress_1 \
      --network A_default wordpress:cli \
      $*
  </code></pre>
  
  <p>does not remove the container after it has done its job, and removing <code>--rm</code> makes me unable to work with the files it has created because I cannot access the volumes of <code>A_wordpress_1</code> because the temporary WP-CLI container has a different working directory.</p>