Skip to content

Docker usages and examples

Terminal window
docker run --name pcore-1 -ti parrotsec/core
Terminal window
docker stop pcore-1
Terminal window
docker start pcore-1
Terminal window
docker rm pcore-1
Terminal window
docker ps -a

Terminal 1:

Terminal window
docker run --name pentest1 -ti parrotsec/security

Terminal 2: ```bash docker run –name pentest2 -ti parrotsec/security

Terminal window
**Terminal 3:** ```bash
docker run --name msf-listener -ti parrotsec/metasploit
Terminal window
docker rm $(docker ps -qa)

Start a container and automatically remove it on exit

Section titled “Start a container and automatically remove it on exit”
Terminal window
docker run --rm -ti parrotsec/core

It is a good practice not to keep persistent Docker containers, but rather to remove them after every use and ensure important files are saved on a Docker volume.

The following command creates a work folder inside the current directory and mounts it to /work inside the container.

Terminal window
docker run --rm -ti -v $PWD/work:/work parrotsec/core

Use Volumes to share files across multiple containers

Section titled “Use Volumes to share files across multiple containers”

Terminal 1:

Terminal window
docker run --name pentest -ti -v $PWD/work:/work parrotsec/security

Terminal 2: ```bash docker run –rm –network host -v $PWD/work:/work -ti parrotsec/security

Terminal window
**Terminal 3:** ```bash
docker run --rm -v $PWD/work:/work -ti parrotsec/metasploit

Open a port from the container to the host

Section titled “Open a port from the container to the host”

Every Docker container has its own network space connected to a virtual LAN.

All the traffic from within the Docker container will be NATed by the host computer.

If you need to expose a port to other machines outside your local computer, use the following example:

Terminal window
docker run --rm -p 8080:80 -ti parrotsec/core

Note that the first port is the port that will be opened on your host, and the second one is the container port to bind to.

Here is a reference for using the -p flag:

Terminal window
-p <host port>:<container port> (e.g. -p 8080:80)
Terminal window
-p <host port>:<container port>/<protocol> (e.g. -p 8080:80/tcp)

In case of multiple addresses on the host network:

Terminal window
-p <address>:<host port>:<container port> (e.g. -p 192.168.1.30:8080:80)

If you need to make the Docker container share the same networking space as the host machine, use the --network host flag as shown below:

Terminal window
docker run --rm --network host -ti parrotsec/core