title: Docker Apache HTTPD with Certbot
body: <p>I'm attempting to run Wordpress on Docker along with MySQL. Here are the contents of the docker-compose.yaml file</p>
  
  <pre><code>version: '3.3'
  services:
     db:
       image: mysql:5.7
       volumes:
         - blog-vol:/var/lib/mysql
       restart: always
       environment:
         MYSQL_ROOT_PASSWORD: secretpass
         MYSQL_DATABASE: wordpress
         MYSQL_USER: wpuser
         MYSQL_PASSWORD: pass
       ports:
         - "3306:3306"
     wordpress:
       depends_on:
         - db
       image: blog:v1
       ports:
         - "80:80"
       restart: always
       environment:
         WORDPRESS_DB_HOST: db:3306
         WORDPRESS_DB_USER: wpuser
         WORDPRESS_DB_PASSWORD: pass
         WORDPRESS_DB_NAME: wordpress
       build:
         context: .
         dockerfile: Dockerfile.blog
  volumes:
      blog-vol: {}
  </code></pre>
  
  <p>blog:v1 (Image built separately)</p>
  
  <pre><code>FROM wordpress:latest
  
  RUN echo 'deb http://deb.debian.org/debian stretch-backports main' &gt;&gt; /etc/apt/sources.list 
  RUN apt-get update -y
  RUN apt-get install -y python-certbot-apache  -t stretch-backports
  </code></pre>
  
  <p>Dockerfile.blog</p>
  
  <pre><code>FROM blog:v1
  RUN certbot certonly -a standalone  --agree-tos  --non-interactive --dry-run --email email@gmail.com --domains "abc.net" 
  </code></pre>
  
  <p>When I run</p>
  
  <pre><code>docker-compose up
  </code></pre>
  
  <p>I see that Apache &amp; MySQL come up and I can access wordpress. But I do not see Dockerfile.blog execute.</p>
  
  <p>I can SSH in to the container and run the command, but of course that will require a restart of Apache, which will kill the container.</p>
  
  <p>I tried running the commands directly. </p>
  
  <p>Here's the docker-compose.yml</p>
  
  <pre><code>version: '3.3'
  services:
     db:
       image: mysql:5.7
       volumes:
         - blog-vol:/var/lib/mysql
       restart: always
       environment:
         MYSQL_ROOT_PASSWORD: secretpass
         MYSQL_DATABASE: wordpress
         MYSQL_USER: wpuser
         MYSQL_PASSWORD: pass
       ports:
         - "3306:3306"
     wordpress:
       depends_on:
         - db
       image: blog:v1
       ports:
         - "80:80"
       restart: always
       environment:
         WORDPRESS_DB_HOST: db:3306
         WORDPRESS_DB_USER: wpuser
         WORDPRESS_DB_PASSWORD: pass
         WORDPRESS_DB_NAME: wordpress
       build: .
       command:
         - /bin/bash
         - -c
         - |
           certbot certonly -a standalone  --agree-tos  --non-interactive --dry-run --email uhsarp@gmail.com --domains "batchu.net"
  volumes:
      blog-vol: {}
  </code></pre>
  
  <p>Here are the logs</p>
  
  <pre><code>...
  db_1         | 2019-04-25T01:34:14.591824Z 0 [Note] mysqld: ready for connections.
  db_1         | Version: '5.7.25'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
  wordpress_1  | Saving debug log to /var/log/letsencrypt/letsencrypt.log
  wordpress_1  | Plugins selected: Authenticator standalone, Installer None
  wordpress_1  | Obtaining a new certificate
  wordpress_1  | Performing the following challenges:
  wordpress_1  | http-01 challenge for abc.com
  wordpress_1  | Waiting for verification...
  wordpress_1  | Cleaning up challenges
  wordpress_1  | IMPORTANT NOTES:
  wordpress_1  |  - The dry run was successful.
  wordpress_1  |  - Your account credentials have been saved in your Certbot
  wordpress_1  |    configuration directory at /etc/letsencrypt. You should make a
  wordpress_1  |    secure backup of this folder now. This configuration directory will
  wordpress_1  |    also contain certificates and private keys obtained by Certbot so
  wordpress_1  |    making regular backups of this folder is ideal.
  wordpress_1  | Saving debug log to /var/log/letsencrypt/letsencrypt.log
  wordpress_1  | Plugins selected: Authenticator standalone, Installer None
  wordpress_1  | Obtaining a new certificate
  wordpress_1  | Performing the following challenges:
  wordpress_1  | http-01 challenge for abc.com
  wordpress_1  | Waiting for verification...
  wordpress_1  | Cleaning up challenges
  wordpress_1  | IMPORTANT NOTES:
  wordpress_1  |  - The dry run was successful.
  blog_wordpress_1 exited with code 0
  wordpress_1  | Saving debug log to /var/log/letsencrypt/letsencrypt.log
  wordpress_1  | Plugins selected: Authenticator standalone, Installer None
  wordpress_1  | Obtaining a new certificate
  wordpress_1  | Performing the following challenges:
  wordpress_1  | http-01 challenge for abc.com
  wordpress_1  | Waiting for verification...
  Gracefully stopping... (press Ctrl+C again to force)
  Stopping blog_wordpress_1   ... done
  Stopping blog_db_1          ... done
  </code></pre>
  
  <p>So the certbot command runs in a loop. Docker thinks that the execution isn't successful. Also Certbot says that the certs folder needs to be backed up. I'm guessing that this needs to be persisted (mounted as a docker volume). Any ideas on cleaning this up?</p>