ERROR: Named Volume "cerbot-etc:/etc/letsencrypt:rw' is used in service "webserver" but no declaration was found in the volumes section

Viewed 1686

I was following the digital ocean tutorial on how to install wordpress with docker-compose.

https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-docker-compose

I copied the docker-compose file the way it was written in the tutorial, double checked the indentation, checked to make sure the lines in question were written the exact way as the tutorial's example, and substituted the "example.com" with my own information.

Despite all of this I get this error.

ERROR: Named Volumne "cerbot-etc:/etc/letsencrypt:rw' is used in service "webserver" but no declaration was found in the volumes section.

My Docker-Compose file

version: '3'

services:
  db:
    image: mysql:8.0
    container_name: db
    restart: unless-stopped
    env_file: .env
    environment:
      - MYSQL_DATABASE=wordpress
    volumes:
      - dbdata:/var/lib/mysql
    command: '--default-authentication-plugin=mysql_native_password'
    networks:
      - app-network

  wordpress:
    depends_on:
      - db
    image: wordpress:5.1.1-fpm-alpine
    container_name: wordpress
    restart: unless-stopped
    env_file: .env
    environment:
      - WORDPRESS_DB_HOST=db:3306
      - WORDPRESS_DB_USER=$MYSQL_USER
      - WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
      - WORDPRESS_DB_NAME=wordpress
    volumes:
      - wordpress:/var/www/html
    networks:
      - app-network

  webserver:
    depends_on:
      - wordpress
    image: nginx:1.15.12-alpine
    container_name: webserver
    restart: unless-stopped
    ports:
      - "80:80"
    volumes:
      - wordpress:/var/www/html
      - ./nginx-conf:/etc/nginx/conf.d
      - certbot-etc:/etc/letsencrypt
    networks:
      - app-network

  certbot:
    depends_on:
      - webserver
    image: certbot/certbot
    container_name: certbot
    volumes:
      - certbot-etc:/etc/letsencrypt
      - wordpress:/var/www/html
    command: certonly --webroot --webroot-path=/var/www/html --email terique@catricestudios.com --agree-tos --no-eff-email --staging -d cateyescollective.com -d www.cateyescollective.com

volumes:
  certbot-etc:
  wordpress:
  dbdata:

networks:
  app-network:
    driver: bridge 

The code from the tutorial

version: '3'

services:
  db:
    image: mysql:8.0
    container_name: db
    restart: unless-stopped
    env_file: .env
    environment:
      - MYSQL_DATABASE=wordpress
    volumes:
      - dbdata:/var/lib/mysql
    command: '--default-authentication-plugin=mysql_native_password'
    networks:
      - app-network

  wordpress:
    depends_on:
      - db
    image: wordpress:5.1.1-fpm-alpine
    container_name: wordpress
    restart: unless-stopped
    env_file: .env
    environment:
      - WORDPRESS_DB_HOST=db:3306
      - WORDPRESS_DB_USER=$MYSQL_USER
      - WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
      - WORDPRESS_DB_NAME=wordpress
    volumes:
      - wordpress:/var/www/html
    networks:
      - app-network

  webserver:
    depends_on:
      - wordpress
    image: nginx:1.15.12-alpine
    container_name: webserver
    restart: unless-stopped
    ports:
      - "80:80"
    volumes:
      - wordpress:/var/www/html
      - ./nginx-conf:/etc/nginx/conf.d
      - certbot-etc:/etc/letsencrypt
    networks:
      - app-network

  certbot:
    depends_on:
      - webserver
    image: certbot/certbot
    container_name: certbot
    volumes:
      - certbot-etc:/etc/letsencrypt
      - wordpress:/var/www/html
    command: certonly --webroot --webroot-path=/var/www/html --email sammy@example.com --agree-tos --no-eff-email --staging -d example.com -d www.example.com

volumes:
  certbot-etc:
  wordpress:
  dbdata:

networks:
  app-network:
    driver: bridge

Any help would be appreciated.

1 Answers

I had a similar problem following a similar tutorial, but I was able to solve it. In my case, I'm using certbotdata as the name of the volume instead of cert-bot that is yours.

My docker-compose.yml file is the following:

version: '3'
services:
  db:
    image: mysql:8.0
    container_name: db
    restart: unless-stopped
    command: '--default-authentication-plugin=mysql_native_password'
    env_file: .env
    environment:
      - MYSQL_DATABASE=$DB_NAME
    ports:
      - "$MYSQL_PORT:3306"
    volumes: 
      - dbdata:/var/lib/mysql
    networks:
      - app-network

  wordpress:
    image: wordpress:5-fpm-alpine
    depends_on:
      - db
    container_name: wordpress
    restart: unless-stopped
    volumes:
      - wordpress:/var/www/html
      - ./theme:/var/www/html/wp-content/themes/$THEME_NAME
    env_file: .env
    environment:
      - WORDPRESS_DB_HOST=db:3306
      - WORDPRESS_DB_USER=$MYSQL_USER
      - WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
      - WORDPRESS_DB_NAME=$DB_NAME
    networks:
      - app-network

  webserver:
    depends_on:
      - wordpress
    image: nginx:1.15.12-alpine
    container_name: webserver
    restart: unless-stopped
    ports:
      - "$PORT:80"
      - "$SSL_PORT:443"
    volumes:
      - wordpress:/var/www/html
      - ./nginx/conf.d:/etc/nginx/conf.d
      - certbotdata:/etc/letsencrypt
    networks:
      - app-network

  certbot:
    depends_on:
      - webserver
    image: certbot/certbot
    container_name: certbot
    volumes:
      - certbotdata:/etc/letsencrypt
      - wordpress:/var/www/html
    command: certonly --webroot --webroot-path=/var/www/html --email youremail@email.com --agree-tos --no-eff-email --force-renewal -d localhost

volumes:
  wordpress:
  dbdata:
  nginx:
  certbotdata:

networks:
  app-network:
    driver: bridge

It looks pretty much the same but is working for me. Also you have to include the .env file to include the environmental variables.

My .env file:

MYSQL_ROOT_PASSWORD=root_password
MYSQL_USER=wordpress
MYSQL_PASSWORD=wordpress_password
DB_NAME=wordpress
PORT=80
SSL_PORT=443
MYSQL_PORT=3306
THEME_NAME=mytheme

It's not necessary to mount the theme directory.

For more detailed instructions in how to setup the nginx.conf file you can follow the whole tutorial.

I hope that this works for you!

Related