【问题标题】:Why does "docker-compose" and "docker run" run in different containers为什么“docker-compose”和“docker run”在不同的容器中运行
【发布时间】:2021-01-12 01:56:50
【问题描述】:

我使用docker run -it seafileltd/seafile-mc:7.1.4 /bin/bash 构建了一个seafile 容器,它运行良好。但是当我使用下面的docker-compose.yaml 运行它时,情况就有些不同了。

version: '2.0'
services:
  seafile:
    image: seafileltd/seafile-mc:7.1.4
    container_name: seafile
    ports:
      - "80:80"

docker-compose 几个目录如下

docker-compose:

[root@felix mmm]# docker exec -it seafile bash
root@6ffb38b7058d:/opt/seafile# ls /shared/
logs  nginx  seafile

码头运行:

[root@felix mmm]# docker run -it seafileltd/seafile-mc:7.1.4 /bin/bash
root@b919cfbb1224:/opt/seafile# ls /shared
ls: cannot access '/shared': No such file or directory

【问题讨论】:

    标签: docker docker-compose


    【解决方案1】:

    当您在示例中运行 docker run 时,您不会运行容器的默认命令,而是运行 bin/bash。

    默认情况下,seafile-mc 容器在容器启动时运行/scripts/start.py,并且该进程将文件写入/opt 文件夹。

    当您运行docker run -it seafileltd/seafile-mc:7.1.4 /bin/bash 时,您运行的是/bin/bash 而不是/scripts/start.py。所以该进程没有运行并写入文件来选择。

    我假设您运行了 docker-compose updocker-compose run seafile,它们运行了 /scripts/start.py,然后写入 opt 文件夹。

    如果您想要一个与您运行的 docker 命令等效的 docker-compose 命令,您可以运行 docker-compose run seafile /bin/bash 并获得与 docker run 命令相同的结果。

    【讨论】:

    • 我知道了,非常感谢。
    猜你喜欢
    • 2021-09-05
    • 1970-01-01
    • 2020-12-07
    • 1970-01-01
    • 2017-03-06
    • 2023-01-22
    • 1970-01-01
    • 2021-12-01
    • 2022-11-18
    相关资源
    最近更新 更多