- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将MySQL数据库还原到具有Apache和MySQL服务的ubuntu docker容器。这是我的 docker 文件
从ubuntu
RUN apt-get update -y
ENV DATABASE_SERVER 'IP'
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get install apache2 -y && apt-get install php7.4 -y && apt-get install mysql-server >
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_RUN_DIR /var/www/html/
COPY ./startup.sh /var/www/
COPY ./db_test.php /var/www/html
COPY ./my_sql_secure.sh /var/www/
COPY ./backup.sql /var/www/html/
RUN bash /var/www/my_sql_secure.sh
COPY ./restoredb.sh /var/www/
CMD bash /var/www/startup.sh
EXPOSE 80
这是我的startup.sh
apache2 -DFOREGROUND | service mysql start | mysql -uroot sentrifugo < /var/www/html/backup.sql
如果我在没有“mysql -uroot sentrifugo 据我所知,CMD仅接受两个命令,并在startup.sh替换它之后运行restored.b。
最佳答案
它实际上取决于您正在构建FROM
的图像,假设它是官方MySQL图像,则只需将COPY
backup.sql
放入种子文件夹:
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions
.sh
,.sql
and.sql.gz
that are found in/docker-entrypoint-initdb.d
. Files will be executed in alphabetical order. You can easily populate your mysql services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by the MYSQL_DATABASE variable.
COPY ./backup.sql /var/www/html/
...至:
COPY ./backup.sql /docker-entrypoint-initdb.d/
如果您使用的是自定义图像,则可能是这样,您可能想要一个
ENTRYPOINT
在启动时执行该导入脚本。
startup.sh
可能会进行一些更改:
service mysql start && \
mysql -uroot sentrifugo < /var/www/html/backup.sql;
apache2 -DFOREGROUND
这将首先启动MySQL服务,然后填充数据库。然后,最后启动Apache。
CMD
的首选形式是exec形式。这会使您的
CMD
看起来像这样:
CMD ["/bin/bash","/var/www/startup.sh"]
(引用:
https://docs.docker.com/engine/reference/builder/#cmd)
关于mysql - 如何在dockerfile中还原MySQL数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62538876/
我正在尝试使用谷歌云构建触发器来构建我的 docker 容器。不幸的是,构建没有找到我的 docker 文件。它不在我的存储库的根目录中,但我认为我可以指定一个相对路径。显然我配置错误了。下面是我的
我可以像这样构建一个 Dockerfile docker build -t deepak/ruby . 但是对于一个不名为Dockerfile的Dockerfile # DOCKER-VERSION
是否可以命名构建阶段?我正在搜索类似以下示例的内容: ARG NAME FROM python:3.7-alpine as modul-${NAME} # ... 如果我尝试这个例子,就会发生这个错误
在我的 Dockerfile 中,我需要使用命令替换来添加一些环境变量。我想设置 ENV PYTHONPATH /usr/local/$(python3 -c 'from distutils impo
以下Dockerfile包含四个COPY层: COPY README.md ./ COPY package.json ./ COPY gulpfile.js ./ COPY __BUILD_NUMBE
我正在尝试从我创建的 Dockerfile 中拉取 tomcat,并使用以下命令拉取 centos: FROM centos RUN docker run -it tomcat 然后现在我正在创建一个
我不确定是否应该为我的 Node.js 应用程序创建不同的 Dockerfile 文件。一种用于没有开发依赖项的生产,另一种用于包含开发依赖项的测试。 或者一个基本上是开发Dockerfile.dev
我拥有的是多个相似且简单的dockerfile 但我想要的是有一个单一的基础 dockerfile 和我的 dockerfile将他们的变量传递给它。 在我的例子中,dockerfile 之间的唯一区
我有一个应用程序有两个 Dockerfile ,说 Dockerfile.foo和 Dockerfile.bar ,预计将为 docker-compose.yml 的两个不同服务生成两个不同的图像.
我是一个 docker maven 插件新手。 如果我理解得很好,根据Spotify's Dockerfile Maven documentation ,应该将 Dockerfile 放在我的项目的根
我正在设置一个docker容器,将在this article之后在nginx服务器上为我的Angular 5应用程序提供服务。 本文提出了这个Dockerfile: # Stage 0, based
大家好, 我是 docker 的新手,我想容器化我的 ASP.NET Core 应用程序,但出现错误,我无法继续构建我的图像 这是我的示例 Dockerfile FROM microsoft/dotn
我想在不使用注册表的情况下链接 Dockerfiles,这可以通过 FROM 实现吗?陈述? 以两个 Dockerfile 为例: Dockerfile /some/other/dir/Dockerf
我尝试在公共(public) dockerhub 上通过我自己的镜像安装 Airflow,但它在本地运行完美,但当我尝试在 Openshift 上使用它时。我在下面收到此错误。 `ERROR: Cou
此 dockerfile 工作正常。但是如何在 dockerfile 中执行命令? FROM alpine RUN apk add --update sqlite && rm -rf /var/cac
当我尝试设置自动构建时,我的 Docker Hub 存储库中的 Dockerfile 为空。如果我触发构建:- Build failed: Dockerfile not found at ./Dock
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题?通过 editing this post 添加详细信息并澄清问题. 1年前关闭。 Improve this
我目前正在将一个巨大的 DockerFile 拆分为单独的 DockerFile,但是在巨大的 DockerFile 中定义的一些变量需要在单独的 DockerFile 中使用。 Docker 是否有
我有一个 Dockerfile 可以创建我想在这里使用的构建镜像:~/build/Dockerfile 然后我使用一个标准镜像来部署 从 ~/build/Dockerfile 构建的图像没有在任何地方
我运行这个: ➜ frontend git:(master) ✗ docker-compose up Building web ERROR: Cannot locate specified Dock
我是一名优秀的程序员,十分优秀!