我自己做了一个Dockerfile和一个docker-compose.yml,并尝试用docker-compose.yml做容器。apache容器工作正常:稳定,但db容器不能。它永远不会成为状态up。
/work_space
|-eccube #docker-compose.yml
| #Dockerfile
|
|-eccube-data #db
#data
#ececcube-2.4.1
#html使用docker logs <db container ID>查看发生了什么↓
Initializing database
2019-05-22T07:59:02.264102Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-05-22T07:59:02.266227Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2019-05-22T07:59:02.267061Z 0 [ERROR] AbortingDockerfile
FROM centos:7
RUN yum update -y
RUN yum install -y sudo
RUN yum install -y epel-release
RUN yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
RUN yum clean all
RUN yum -y install wget
RUN yum -y install httpd
RUN yum -y install --enablerepo=remi,remi-php52 php php-devel php-mbstring php-pdo php-gd php-xml php-mcrypt php-pgsql
RUN wget http://downloads.ec-cube.net/src/eccube-2.4.1.tar.gz
RUN tar zxvf eccube-2.4.1.tar.gz
RUN mv -f /eccube-2.4.1/data/ /var/www/data
RUN mv -f /eccube-2.4.1/html/ /var/www/html
RUN rm -rf eccube-2.4.1
RUN rm -rf eccube-2.4.1.tar.gz
CMD ["/usr/sbin/httpd", "-DFOREGROUND"]
EXPOSE 80docker-compose.yml
version: '3'
services:
apache:
build: .
privileged: true
tty: true
ports:
- 80:80
volumes:
- /work_space/eccube-data/html:/var/www/html
- /work_space/eccube-data/data:/var/www/data
db:
image: mysql:5.7
privileged: true
tty: true
ports:
- 6666:3306
volumes:
- /work_space/eccube-data/db:/var/lib/mysql
environment:
- MYSQL_DATABASE:'cube2_dev'
- LANG=C.UTF-8
- MYSQL_ROOT_PASSWORD=root我将向您展示解决此问题所需的代码/文件。
/w/eccube ❯❯❯ docker ps ✘ 1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
251df77751fe eccube_apache "/usr/sbin/httpd -DF…" About an hour ago Up About an hour 0.0.0.0:80->80/tcp eccube_apache_1
/w/eccube ❯❯❯ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b857c8b211ca mysql:5.6 "docker-entrypoint.s…" About an hour ago Exited (1) About an hour ago eccube_db_1
251df77751fe eccube_apache "/usr/sbin/httpd -DF…" About an hour ago Up About an hour 0.0.0.0:80->80/tcp eccube_apache_1在var/lib/mysql中,这些文件和目录存在。
root@f4680fa4d3f4:/var/lib/mysql# ls
auto.cnf ca.pem client-key.pem ib_logfile0 ibdata1 mysql private_key.pem server-cert.pem sys
ca-key.pem client-cert.pem ib_buffer_pool ib_logfile1 ibtmp1 performance_schema public_key.pem server-key.pem然后,在/work_space/eccube_data/db中,这些我们实际上是同步的!
/w/e/db ❯❯❯ ls
auto.cnf ca.pem client-key.pem ib_logfile0 ibdata1 mysql private_key.pem server-cert.pem sys
ca-key.pem client-cert.pem ib_buffer_pool ib_logfile1 ibtmp1 performance_schema public_key.pem server-key.pem发布于 2019-05-22 22:12:18
使用Docker for Mac时,以下内容将数据存储在嵌入式VM中,因为此目录没有映射到您的Mac环境:
- /work_space/eccube-data/html:/var/www/html
- /work_space/eccube-data/data:/var/www/data和
- /work_space/eccube-data/db:/var/lib/mysql相反,您希望使用相对路径:
- ../eccube-data/html:/var/www/html
- ../eccube-data/data:/var/www/data和
- ../eccube-data/db:/var/lib/mysql这里假设您从eccube目录内部运行docker-compose命令,并且您的项目位于区分大小写的/Users目录中(请参阅有关在Docker for Mac getting started guide中使用其他目录的更多信息)。
发布于 2019-05-23 13:02:46
我删除了container、image和volume,然后执行了docker-compose up -d。啊,真灵。现在我有了正确的容器。
非常感谢!
https://stackoverflow.com/questions/56252943
复制相似问题