它适用于 ubuntu 镜像
wolf@linux:~$ docker run -it ubuntu /bin/bash
root@00e6296d31d8:/#
但是,当我尝试使用不同的图像时vulnerables/web-dvwa
,它不再起作用
wolf@linux:~$ docker run -it vulnerables/web-dvwa /bin/bash
[+] Starting mysql...
[ ok ] Starting MariaDB database server: mysqld.
[+] Starting apache
[....] Starting Apache httpd web server: apache2AH00558: 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
. ok
==> /var/log/apache2/access.log <==
==> /var/log/apache2/error.log <==
[Sat Apr 03 11:54:24.321232 2021] [mpm_prefork:notice] [pid 307] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Sat Apr 03 11:54:24.321280 2021] [core:notice] [pid 307] AH00094: Command line: '/usr/sbin/apache2'
==> /var/log/apache2/other_vhosts_access.log <==
id
whoami
此容器中没有 bash shell
wolf@linux:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
820d3a292b2c vulnerables/web-dvwa "/main.sh /bin/bash" 11 seconds ago Up 11 seconds 80/tcp upbeat_visvesvaraya
wolf@linux:~$
答案1
您可以使用以下方式附加到容器:
docker exec -ti 820d3a292b2c bash
或者:
docker exec -ti upbeat_visvesvaraya bash
答案2
您尝试运行的映像包含vulnerables/web-dvwa
在ENTRYPOINT ["/main.sh"]
启动时运行 mysqld 的映像。如果您只需要该映像中的 shell,则可以覆盖主条目,如下所示...
docker run -it --rm --entrypoint /bin/bash vulnerables/web-dvwa
或者,如果您想要在正在运行的 mysqld 容器上使用 shell,您可以正常运行它(不带-it
参数),然后执行以下操作以在正在运行的容器中获取 bash shell。
docker exec -it <container_id> /bin/bash