mysql - 切勿将容器设置为 'up' [docker]

标签 mysql apache docker docker-compose centos

我做了一个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] Aborting

Dockerfile

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 80

docker-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

最佳答案

使用 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 中的其他目录)。

关于mysql - 切勿将容器设置为 'up' [docker],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56252943/

相关文章:

docker - 使用图像查找 docker 容器?

php - 使用函数中的查询结果显示/隐藏 div

php - 使用 htaccess 将 Javascript 转换为 php 处理程序页面

angular - 在Docker Windows容器中运行的.Net核心Angular应用

mongodb - mongod --bind_ip 使用 docker-compose 版本 2

php - URL 重写 : css, js,图片未加载

如果特定日期不存在,MySQL 查询将针对属性返回零

php - 从 MYSQL 中获取数据并显示在 JSON 文件中

mysql - 从 MYSQL 选择 Point 数据类型

javascript - 调试消息 "Resource interpreted as other but transferred with MIME type application/javascript"