[英]Docker-compose won't start MySQL if I define a volume
I'm trying to create a volume for my MySQL container so the data can persist.我正在尝试为我的 MySQL 容器创建一个卷,以便数据可以保留。 So in my docker-compose, I created a volume in which the data will be stored.所以在我的 docker-compose 中,我创建了一个存储数据的卷。
Here's my docker-compose:这是我的 docker-compose:
version: '3'
services:
app:
build:
context: .
dockerfile: .docker/Dockerfile
image: portfolio
ports:
- 80:80
volumes:
- .:/var/www/html
links:
- mysql
environment:
DB_HOST: mysql
DB_DATABASE: blog
DB_USERNAME: blog
DB_PASSWORD: ...
mysql:
image: mysql:5.7
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: blog
MYSQL_USER: blog
MYSQL_PASSWORD: ...
MYSQL_ROOT_PASSWORD: ...
volumes:
- "./db:/var/lib/mysql"
The volume is defined at the end of the file.卷在文件末尾定义。 Unfortunately, that's not working.不幸的是,这行不通。 If I do a docker container ls
it only shows the portfolio container, and if I do a docker container ls -a
it does show my the container for MySQL, but it says it has "exited" right after I did the docker-compose up -d
, so apparently it was started but then immediately crashed or something. If I do a docker container ls
it only shows the portfolio container, and if I do a docker container ls -a
it does show my the container for MySQL, but it says it has "exited" right after I did the docker-compose up -d
,所以显然它已经启动但随后立即崩溃或其他东西。
If I remove the last 2 lines related to the MySQL volume, it works fine.如果我删除与 MySQL 卷相关的最后 2 行,它工作正常。 My containers are both up and the app works normally.我的容器都启动了,应用程序正常运行。 So basically what causes the container to crash is the volume, so maybe I didn't define it correctly.所以基本上导致容器崩溃的原因是音量,所以也许我没有正确定义它。 What do you think?你怎么看?
I found on my Windows system that although my local volume (ie/db) looked empty it really wasn't.我在我的 Windows 系统上发现,虽然我的本地卷 (ie/db) 看起来是空的,但实际上并非如此。 I wound up running ls -la
from a bash shell on the same folder it showed a.sock file in it.我最终从 bash shell 运行ls -la
在它显示一个 .sock 文件的同一文件夹中。 Once I removed ( rm -f *.sock
) that and ran docker-compose up --build
it seemed to mount the volume properly一旦我删除( rm -f *.sock
)并运行docker-compose up --build
它似乎正确安装了卷
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.