我遇到了挂载文件的问题,与目录非常相似。具体问题与Wordpress's official image和文件 wp-config.php (或任何其他)有关。
以下是 docker-compose.yml 文件的内容:
web:
image: wordpress
ports:
- "80:80"
volumes:
- ./src/wordpress/wp-content:/var/www/html/wp-content
- ./src/wordpress/wp-config.php:/var/www/html/wp-config.php
environment:
WORDPRESS_DB_NAME: dummyname
links:
- db:mysql
db:
image: mysql
ports:
- "3306:3306"
volumes:
- mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: dummypass
当我运行命令 docker-compose up 或 docker run 输出时是相同的:
WordPress not found in /var/www/html - copying now...
WARNING: /var/www/html is not empty - press Ctrl+C now if this is an error!
+ ls -A
wp-config.php
+ sleep 10
Complete! WordPress has been successfully copied to /var/www/html
sed: couldn't edit wp-config.php: not a regular file
在这两种情况下,都会创建 wp-config.php / ,但是作为目录而不是文件。
有时候错误可能是:
ERROR: Cannot start container <container id>: [9] System error: not a directory
如果我评论正在挂载 wp-config.php 文件的行,则一切都按预期工作。
docker inspect 会提供正确的信息:
"HostConfig": {
"Binds": [
"/home/dummyuser/projects/dummyproject/src/wordpress/wp-config.php:/var/www/html/wp-config.php:rw"
],
...
"Mounts": [
{
"Source": "/home/dummyuser/projects/dummyproject/src/wordpress/wp-config.php",
"Destination": "/var/www/html/wp-config.php",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
},
{
"Name": "b8649d2edbfb043a05bce96622fbbc1c10b24b9f65736407efe961c3ec550b7a",
"Source": "/var/lib/docker/volumes/b8649d2edbfb043a05bce96622fbbc1c10b24b9f65736407efe961c3ec550b7a/_data",
"Destination": "/var/www/html",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
环境:
Linux 3.19.0-56-generic #62~14.04.1-Ubuntu SMP Fri Mar 11 11:03:15 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Docker version 1.10.3, build 20f81dd
docker-compose version 1.5.2, build 7240ff3
我尝试过的事情,并没有得到任何结果:
不太确定,但在entrypoint script上观看时,如果在将Wordpress tar存档提取到/ var / www / html之前执行挂载,则可能是 wp-config.php <的原因/ em>文件(或任何其他)无法找到并因此安装。对于目录,它似乎不是问题。
答案 0 :(得分:0)
您可以尝试更灵活的方法,按如下方式构建自己的图像:
在 docker-compose.yml :
中web:
build: .
ports:
- "80:80"
volumes:
- ~/workspace/wordpress-dir:/var/www/html
environment:
WORDPRESS_DB_NAME: dummyname
links:
- db:mysql
db:
image: mysql
ports:
- "3306:3306"
volumes:
- mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: dummypass
然后在 Dockerfile 的同一文件夹中写如下:
FROM wordpress
# Copying wp-content dir files
COPY src/wordpress/wp-content/* /var/www/html/wp-content/
之后你需要在之前构建,以避免wordpress-entrypoint替换,只是第一次,如下所示:
docker-compose build
docker-compuse up
我认为这种构建容器的方式可以为您提供更多的灵活性,并为您的wordpress应用内容提供真正的封装。
此致