Docker – How to run docker container with bash shell

docker

It works with ubuntu image

wolf@linux:~$ docker run -it ubuntu /bin/bash
root@00e6296d31d8:/# 

However, when I try it with different image such as vulnerables/web-dvwa, it doesn't work anymore

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

There is no bash shell in this container

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:~$ 

Best Answer

You can attach to the container with:

 docker exec -ti 820d3a292b2c bash

or:

 docker exec -ti upbeat_visvesvaraya bash