1

I tried using networks, but the network with the folder's name concatenated with "_default" is not found.

If I specify the network like this:

  wpcli:
    container_name: ...
    image: wordpress:cli
    working_dir: /var/www/html
    depends_on:
      - db
      - wordpress
    networks:
      - A_default

I get:

ERROR: Service "wpcli" uses an undefined network "A_default"

although A_default exists in the output of docker network ls.

If I remove the part:

    networks:
      - A_default

I get this error:

wpcli_1 | Error: This does not seem to be a WordPress installation.

wpcli_1 | Pass --path=path/to/wordpress or run wp core download.

A_wpcli_1 exited with code 1

and only this error in the docker-compose up output.

If I use

    volumes:
      - /var/www/html

inside the wpcli section of my docker-compose.yml I get the same error.

docker-compose.yml

Below is my docker-compose.yml with sensible information replaced with ...:

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:

Thank you.

Update 1

I have seen this file but I do not find it helpful in my situation.

Update 2

I wish to use a separate container just for WP-CLI because the command

docker run -it --rm \
    --volumes-from A_wordpress_1 \
    --network A_default wordpress:cli \
    $*

does not remove the container after it has done its job, and removing --rm makes me unable to work with the files it has created because I cannot access the volumes of A_wordpress_1 because the temporary WP-CLI container has a different working directory.

silviubogan
  • 3,343
  • 3
  • 31
  • 57

1 Answers1

0

I see two problems in your docker-compose file:

  1. (removed) networks section was malformed
  2. ./html not mounted in wpcli service

I would try the following:

version: '3.3'

services:
  db:
    ...
  phpmyadmin:
    ...
  wordpress:
    ...
  wpcli:
    ...
    volumes:
      - type: bind
        source: ./html
        target: /var/www/html
        volume:
          nocopy: true
    ...
volumes:
  db_data:

networks:
  A_default:
breakthewall
  • 183
  • 6