我正在尝试在Docker和MySQL上运行Wordpress。这是docker-compose.yaml文件的内容
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: {}
blog:v1(图像单独构建)
FROM wordpress:latest
RUN echo 'deb http://deb.debian.org/debian stretch-backports main' >> /etc/apt/sources.list
RUN apt-get update -y
RUN apt-get install -y python-certbot-apache -t stretch-backports
Dockerfile.blog
FROM blog:v1
RUN certbot certonly -a standalone --agree-tos --non-interactive --dry-run --email email@gmail.com --domains "abc.net"
我跑步时
docker-compose up
我看到Apache&MySQL出现了,我可以访问wordpress了。但是我看不到Dockerfile.blog执行。
我可以通过SSH进入容器并运行命令,但是当然这需要重启Apache,这将杀死容器。
我尝试直接运行命令。
这是docker-compose.yml
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: {}
这是日志
...
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
因此certbot命令循环运行。 Docker认为执行不成功。另外,Certbot还说需要备份certs文件夹。我猜想这需要持久化(作为docker卷安装)。有清理思路吗?