【问题标题】:How can i use exec for contrainer bash when the container won't start in Docker?当容器无法在 Docker 中启动时,如何将 exec 用于容器 bash?
【发布时间】:2019-08-14 00:40:40
【问题描述】:

我尝试运行 php:apache 容器。然后我应用虚拟主机设置并退出容器 bash,我使用了docker restart <containerid>,但我无法启动。然后我用docker logs <containerid>检查了日志,它说你在000-default.conf中有一个语法

现在这是我的问题:如果我无法启动容器,我如何连接容器 bash 并打开 000-default.conf 并修复语法错误?有没有其他办法呢?

这是日志输出:

C:\Users\Utku>docker logs bb
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Sat Mar 23 01:05:26.411235 2019] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.2.16 configured -- resuming normal operations
[Sat Mar 23 01:05:26.411274 2019] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
[Sat Mar 23 01:05:37.388586 2019] [autoindex:error] [pid 16] [client 172.17.0.1:40982] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive
localhost:80 172.17.0.1 - - [23/Mar/2019:01:05:37 +0000] "GET / HTTP/1.1" 403 501 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
localhost:80 172.17.0.1 - - [23/Mar/2019:01:05:37 +0000] "GET /favicon.ico HTTP/1.1" 404 500 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
localhost:80 172.17.0.1 - - [23/Mar/2019:01:06:55 +0000] "GET / HTTP/1.1" 200 286 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
[Sat Mar 23 01:07:53.847828 2019] [mpm_prefork:notice] [pid 1] AH00169: caught SIGTERM, shutting down
AH00526: Syntax error on line 35 of /etc/apache2/sites-enabled/000-default.conf:
Invalid command 'sadasd', perhaps misspelled or defined by a module not included in the server configuration

【问题讨论】:

标签: docker


【解决方案1】:

编辑: docker cp 也应该适用于停止的容器,您可以将配置文件复制出容器,编辑并复制回来。

是的,但是您需要从这个容器创建一个图像并运行它:

  1. 使用docker ps -a查找失败容器的id,例如:d391b29f5526
  2. 运行 docker commit d391b29f5526 test-image 以从此容器创建映像。
  3. docker run -it --entrypoint bash test-image 并进行编辑。
  4. 将步骤 3 中创建的容器提交到映像并运行它。

【讨论】:

    【解决方案2】:

    尝试以下方法:

    docker cp bb:/etc/apache2/sites-enabled/000-default.conf /tmp/000-default.conf
    

    现在,编辑您的 /tmp/000-default.conf(在您的 docker 主机上)并删除它 sadasd 在您的第 35 行,如日志中所述;

    编辑后,将文件复制回容器:

    docker cp /tmp/000-default.conf bb:/etc/apache2/sites-enabled/000-default.conf
    

    如果您的 conf 文件没有错误,现在您应该可以重新启动容器了。

    【讨论】:

      猜你喜欢
      • 2014-09-24
      • 2017-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-28
      相关资源
      最近更新 更多