Docker-compose 的 mariadb 更改后无法重新启动(退出代码 1) [英] Docker-compose's mariadb cannot reboot after change (exit code 1)

查看:56
本文介绍了Docker-compose 的 mariadb 更改后无法重新启动(退出代码 1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这个 github 学习 docker-compose.
https://github.com/lusehair/42inception.git

(在 Ubuntu 下运行良好.想运行时请在 Ubuntu 下运行!)
首先,它运作良好.
但是如果我编辑一个页面并重新启动,就会出现错误.
(docker-compose down 在其他终端,sudo systemctl stop mysql 关闭mysql.)
: 我认为 sudo systemctl stop mysql 可以停止我的 mariadb 服务.但如果不是,请在评论中告诉我.

I'm studying docker-compose with this github.
https://github.com/lusehair/42inception.git

(It works well in Ubuntu. Please run in Ubuntu when you want to run!)
In first, it works well.
But if i edit a page and reboot, there is an error.
(docker-compose down in other terminal, sudo systemctl stop mysql to turn off mysql.)
: I thought sudo systemctl stop mysql could stop my mariadb service. But if not, please tell me in comment.

srcs_mariadb_1 exited with code 1
srcs_mariadb_1 exited with code 1
srcs_mariadb_1 exited with code 1
srcs_mariadb_1 exited with code 1
...

我认为这是因为 ~/data/ 文件夹没有很好地删除造成的.
但我不想删除数据文件夹.
如果我重新启动 docker-compose,甚至是 Ubuntu,我想维护 wp 更改!

评论中的事情
问:为什么我只在 Ubuntu 中运行我的 docker-compose 程序?
A. 我知道仅在 Ubuntu 操作系统中启动 docker 是合乎逻辑的问题.但我这样说有两个原因.首先,我的一些命令应该在 linux os 中启动.其次,我的主题要求我在虚拟机中启动我的 docker-compose 项目.我为此选择了 Ubuntu.

我还尝试更具体地进行调试,如下所示.
开始之前(基本):
: 在根目录运行make.
它清理 docker &数据文件夹、设置和构建.

I think this has caused because ~/data/ folder hasn't deleted well.
But i don't want to delete data folder.
I want to maintain wp changes if i reboot docker-compose, even Ubuntu!

Edit : things in comment
Q. Why do i run my docker-compose program in Ubuntu only?
A. I know it is logical problem that launching docker only in Ubuntu OS. But i said like this because of two reasons. First, some of my command should be launched in linux os. Second, my subject requires me to launch my docker-compose project in a Virtual Machine. I choosed Ubuntu for that.

I also tried to debug more specifically, like below.
BEFORE START (BASIC):
: Run make in root directory.
 It cleans docker & data folder, setup, and build.

  • docker-compose up mariadb
    恐怕为什么这行得通...
kkim@kkim-VirtualBox:~/inception/lusehair/srcs$ docker-compose up mariadb
Creating network "srcs_vpcbr" with driver "bridge"
Creating srcs_mariadb_1 ... done
Attaching to srcs_mariadb_1
mariadb_1    | 2021-06-27 17:18:52 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 8 ...
kkim@kkim-VirtualBox:~/inception/lusehair/srcs$

  • docker-compose up wordpress
    我在 docker-compose up mariadb 成功后尝试了.
    这给了我问题.
    这与其他错误有所不同.
    它一直试图连接几分钟.我几乎在 10 分钟后停止了此操作.
  • kkim@kkim-VirtualBox:~/inception/lusehair/srcs$ docker-compose up wordpress
    srcs_mariadb_1 is up-to-date
    Creating srcs_wordpress_1 ... done
    Attaching to srcs_wordpress_1
    ^CGracefully stopping... (press Ctrl+C again to force)
    Stopping srcs_wordpress_1 ... done
    

    • docker-compose up mariadb wordpress
      它像往常一样给了我错误.. :(
    • kkim@kkim-VirtualBox:~/inception/lusehair/srcs$ docker-compose up mariadb wordpress
      srcs_mariadb_1 is up-to-date
      Starting srcs_wordpress_1 ... done
      Attaching to srcs_mariadb_1, srcs_wordpress_1
      mariadb_1    | 2021-06-27 17:18:52 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 8 ...
      mariadb_1    | 2021-06-27 17:18:56 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 8 ...
      mariadb_1    | 2021-06-27 17:18:59 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 9 ...
      mariadb_1    | 2021-06-27 17:19:02 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 9 ...
      mariadb_1    | 2021-06-27 17:19:06 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 8 ...
      mariadb_1    | 2021-06-27 17:19:11 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 8 ...
      mariadb_1    | 2021-06-27 17:19:17 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 7 ...
      mariadb_1    | 2021-06-27 17:19:26 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 9 ...
      mariadb_1    | 2021-06-27 17:19:41 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 8 ...
      mariadb_1    | 2021-06-27 17:20:10 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 9 ...
      mariadb_1    | 2021-06-27 17:21:04 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 9 ...
      mariadb_1    | 2021-06-27 17:22:06 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 8 ...
      mariadb_1    | 2021-06-27 17:23:09 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 8 ...
      mariadb_1    | 2021-06-27 17:24:12 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 7 ...
      mariadb_1    | 2021-06-27 17:25:15 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 8 ...
      mariadb_1    | 2021-06-27 17:26:18 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 8 ...
      srcs_mariadb_1 exited with code 1
      mariadb_1    | 2021-06-27 17:28:24 0 [Note] mysqld (mysqld 10.3.29-MariaDB-0+deb10u1) starting as process 7 ...
      ^CGracefully stopping... (press Ctrl+C again to force)
      Stopping srcs_wordpress_1 ... done
      Stopping srcs_mariadb_1   ... done
      


      感谢您在此之前阅读.
      我已连接到 git 存储库的所有者,但它在他的 ubuntu 中运行良好.
      我会尝试重新安装我的操作系统并在这个问题中写道.

      如果我误解了什么,请告诉我!!!
      我想我是,但我不知道重点.

      这是 docker-compose.yml.
      它仅使用本地映像 (Dockerfile).


      Thank you for reading until this.
      I have connected to git repository's owner, but it's working well in his ubuntu.
      I will try to reinstall my os and wrote in this question.

      Please tell me if i'm misunderstanding something!!!
      I think i am, but i don't know the point.

      This is docker-compose.yml.
      It uses local images (Dockerfile) only.

      # docker-compose.yml
      version: '3'
      services:
          mariadb:
              image: mariadb:inc
              volumes:
                  - ~/data/maria:/var/lib/mysql
              restart: always
              environment:
                  MARIA_LOGIN: "${MARIA_LOGIN}"
                  MARIA_PASS: "${MARIA_PASS}"
              ports: 
                  - "3306:3306"
              build:
                  context: ./requirements/mariadb
                  dockerfile: Dockerfile 
              networks:
                  vpcbr:
              env_file: .env
                     
      
          wordpress:
              depends_on:
                  - mariadb
              image: wordpress:inc
              volumes:
                  - ~/data/wp:/var/www/wordpress
              restart: always
              environment:
                  WP_LOGIN: "${WP_LOGIN}"
                  WP_PASS: "${WP_PASS}"
                  WPU_1LOGIN: "${WPU_1LOGIN}"
                  WPU_1PASS: "${WPU_1PASS}"
                  MARIA_LOGIN: "${MARIA_LOGIN}"
                  MARIA_PASS: "${MARIA_PASS}"
              ports:
                  - "9000:9000"
              build:
                  context: ./requirements/wordpress
                  dockerfile: Dockerfile
              networks:
                  vpcbr:
              env_file: .env
          nginx:
              image: nginx:inc
              restart: always
              depends_on:
                  - wordpress
              ports:
                   - "443:443"
              volumes:
                  - ~/data/wp:/var/www/wordpress
              build:
                  context: ./requirements/nginx
                  dockerfile: Dockerfile
              networks:
                  vpcbr:
              extra_hosts:
                  - "lusehair.42.fr:127.0.0.1"
              env_file: .env
      
      networks:
          vpcbr:
              driver: bridge
      


      这是 Mariadb 的 Dockerfile,setup.sh.
      您可以在 github 中查看所有项目文件.


      And this is Mariadb's Dockerfile, setup.sh.
      You can see all project files in github.

      FROM debian:buster 
      
      MAINTAINER lusehair <lusehair@42.student.fr>
      
      RUN apt-get update
      RUN apt-get install -y mariadb-server vim procps; 
      
      COPY tools/setup.sh . 
      RUN chmod +x setup.sh 
      
      EXPOSE 3306
      RUN rm /etc/mysql/mariadb.conf.d/50-server.cnf 
      # Swith off the bind address 
      COPY tools/50-server.cnf /etc/mysql/mariadb.conf.d 
      ENTRYPOINT ["sh", "/setup.sh"]
      

      if [ ! -d "/var/lib/mysql/wordpress" ]; then 
          
          mysql_install_db
          service mysql start
          
          mysql -e "CREATE USER '${MARIA_LOGIN}'@'localhost' identified by '${MARIA_PASS}';" &&
          mysql -e "CREATE DATABASE IF NOT EXISTS wordpress;" &&
          mysql -e "GRANT ALL PRIVILEGES ON *.* TO '${MARIA_LOGIN}'@'%' IDENTIFIED BY '${MARIA_PASS}';" &&
          mysql -e "FLUSH PRIVILEGES;"
          service mysql stop 
      fi
      #sleep 5
      mysqld
      

      推荐答案

      你应该不需要暴露 3306 端口.

      You shouldn't need to expose 3306 port.

      您的 setup.sh 创建一个与它授予权限的用户不同的用户.容器不适合运行服务.

      Your setup.sh creates a different user to that one that it gives grants to. Containers aren't good for running services.

      有一个使用官方图片的好案例.

      There's a good case for using the official images.

      version: '3'
      services:
          mariadb:
              image: mariadb:10.5.11
              volumes:
                  - ~/data/maria:/var/lib/mysql
              restart: always
              environment:
                  MARIADB_USER: "${MARIA_LOGIN}"
                  MARIADB_PASSWORD: "${MARIA_PASS}"
                  MARIADB_DATABASE: wordpress
      

      但是不要遇到太多错误/学习的东西 :-)

      Don't get as many errors/learning things however :-)

      从您的存储库看来,您也解决了其余问题(包括官方图片的 wordpress).

      From your repository it looks like you resolved the rest too (include wordpress which is an official image).

      这篇关于Docker-compose 的 mariadb 更改后无法重新启动(退出代码 1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆