Docker 当我使用构建命令时,compose 忽略了我的 Docker 文件

Docker compose ignores my Dockerfile when I use the build command

我有这个文件夹结构:

/home/me/composetest /home/me/composetest/mywildflyimage

内部复合材料我有这个 docker-compose.yml:

web:
    image: test/mywildfly
    container_name: wildfly
    ports:
        - "8080:8080"
        - "9990:9990"

在 mywildflyimage 中我有这张 docker 图片:

FROM jboss/wildfly

EXPOSE 8080 9990

ADD standalone.xml /opt/jboss/wildfly/standalone/configuration/

RUN /opt/jboss/wildfly/bin/add-user.sh admin admin --silent 
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]

如果我运行

docker built -t test/mywildfly .
docker-compose up

一切正常,管理部分被设置为 0.0.0.0(CMD 命令的 -bmanagement 0.0.0.0 部分)。

如果我改变我的 docker-compose.yml:

web:
        build: mywildflyimage
        container_name: wildfly
        ports:
            - "8080:8080"
            - "9990:9990"

和运行 docker-撰写

它仍然可以启动,但管理部分不再绑定到 0.0.0.0(这是我从中继承的图像的默认行为)。

为什么我在docker-compose.ml中使用build命令时它停止工作?

编辑:它似乎忽略了我所有的 docker 文件命令。

在输入 docker-compose up 之前,您应该使用 docker-compose build [options] [SERVICE...] 构建图像。

Options:
--force-rm  Always remove intermediate containers.
--no-cache  Do not use cache when building the image.
--pull      Always attempt to pull a newer version of the image.

对于您的情况,例如:docker-compose build --no-cache web

运行 docker-compose build 更改后 docker-comopse.yml 然后 docker-compose up