当容器无法在Docker中启动时,如何使用exec进行约束bash?

时间:2019-03-23 00:54:43

标签: docker

我尝试运行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

2 个答案:

答案 0 :(得分:0)

编辑: docker cp也应在停止的容器上运行,您可以将配置文件从容器中复制出来,进行编辑,然后再复制回来。

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

  1. 使用docker ps -a查找失败的容器的ID,例如:d391b29f5526
  2. 运行docker commit d391b29f5526 test-image从该容器中创建一个图像。
  3. docker run -it --entrypoint bash test-image并进行编辑。
  4. 将在第3步中创建的容器提交给映像,然后运行它。

答案 1 :(得分:0)

尝试以下操作:

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

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

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

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

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