Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Docker容器保留数据_Docker_Dockerfile_Lamp - Fatal编程技术网

Docker容器保留数据

Docker容器保留数据,docker,dockerfile,lamp,Docker,Dockerfile,Lamp,我正在学习Docker,我正在为Ubuntu容器制作Dockerfile 我的问题是我一直在不同容器之间获取持久信息。我已退出,删除了容器,然后删除了其图像。对Dockerfile进行更改后,我执行了docker build-t playbuntu.执行以下Dockerfile: FROM ubuntu:latest ## for apt to be noninteractive ENV DEBIAN_FRONTEND noninteractive ENV DEBCON

我正在学习Docker,我正在为Ubuntu容器制作Dockerfile

我的问题是我一直在不同容器之间获取持久信息。我已退出,删除了容器,然后删除了其图像。对Dockerfile进行更改后,我执行了
docker build-t playbuntu.
执行以下Dockerfile:

FROM ubuntu:latest

    ## for apt to be noninteractive
    ENV DEBIAN_FRONTEND noninteractive
    ENV DEBCONF_NONINTERACTIVE_SEEN true

    ## preesed tzdata, update package index, upgrade packages and install needed software
    RUN echo "tzdata tzdata/Areas select Europe" > /tmp/preseed.txt; \
        echo "tzdata tzdata/Zones/Europe select London" >> /tmp/preseed.txt; \
        debconf-set-selections /tmp/preseed.txt && \
        apt-get update && \
        apt-get install -y tzdata


    RUN apt-get update -y && apt-get upgrade -y && apt-get install tree nano vim -y && apt-get install less -y && apt-get install lamp-server^ -y

    RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf

    EXPOSE 80

    WORKDIR /var/www

    COPY ./index.php /var/www
    COPY ./000-default.conf /etc/apache2/sites-available

    CMD [ "apache2ctl", "start", "&&", "apache2ctl", "restart" ]
执行
winpty docker run-it-p 80:80 playbuntu bash
后,我的问题是,不是我的index.php文件输出以下内容:

<?php

    print "<center><h3>Sisko's LAMP activated!</h3><center>";

    phpinfo();

您可以使用卷来保存一些文件夹,如配置或属性等。

我怀疑,在您更改主机上的
index.php
之后,您没有重新运行
docker build…
命令。您需要在图像内容发生任何更改时重新创建容器图像

请确认是否再次运行
docker build…
命令可以解决此问题

背景 Docker图像包含多个层中的一个

图像(层)和卷是不同的

由于您的
docker run…
命令不包含任何内容,例如
--volume=
bind mounts(或等效内容),我怀疑docker卷与此问题无关

有一种可能性是重建图像不会替换图像层,因此会发生缓存。然而,就你而言,我认为这不是问题所在。有关添加图层的Dockerfile命令的概述,请参见Docker文档()

由于层的工作方式,如果Docker文件中前面的层未更改
index.php
未更改,则Docker不会重建这些层。但是,由于Dockerfile包含一个层,
apt get update&&apt get install….
,因此该层将无效并重新创建,后续层也将无效

如果您在主机上更改
index.php
并重建图像,则此层将始终重建

我创建了你的Dockerfile两次。下面是第二个(!)构建命令的开始。注意,
运行apt get update…
层之前的未更改层的
使用cache
命令,该层将重建

docker build--rm-f“Dockerfile”-t59582820:0939“
将生成上下文发送到Docker守护程序3.584kB
步骤1/10:来自ubuntu:最新版本
--->549b9b86cb8d
步骤2/10:环境DEBIAN_前端非交互
--->使用缓存
--->1529d0e293f3
步骤3/10:ENV DEBCONF_非交互_视为真
--->使用缓存
--->1ba10410d06a
步骤4/10:运行echo“tzdata tzdata/Areas select Europe”>/tmp/preseed.txt;echo“tzdata tzdata/Zones/Europe select London”>>>/tmp/preseed.txt;debconf set selections/tmp/preseed.txt&&apt-get-update&&apt-get-install-y-tzdata
--->使用缓存
--->afb861da52e4
步骤5/10:运行apt get update-y&&apt get upgrade-y&&apt get install tree nano vim-y&&apt get install less-y&&apt get install lamp server^-y
--->在6F05BB8E80A中运行

有证据表明,在更改index.php之后,您没有进行重建。

谢谢。我再次运行它,但我绝对肯定每次我都会删除我的ubuntu映像并执行docker build。另外,最初我试图创建一个连接,允许我从Windows编辑容器文件。这不起作用,所以,这是一个奇怪的结果。尽管我断言我一直在重建图像,但这次我在index.php中获得了正确的内容。但是,我退出并删除了该容器,并从同一图像创建了第二个容器。这次唯一的不同之处是我添加了-v c:/localfile system:/var/www来尝试从windows编辑容器代码。现在,index.php再次显示调试代码。。。Docker图像和容器之间也存在差异。运行映像时,它会创建一个容器。可以从同一图像创建多个容器。我认为您的问题在于您没有重建图像,因此从中创建的任何容器都使用了原始的
index.php
<?php

    print "...responding";

    phpinfo();