Docker usages and examples
Launch a container
Section titled “Launch a container”docker run --name pcore-1 -ti parrotsec/coreStop the container
Section titled “Stop the container”docker stop pcore-1Resume a previously stopped container
Section titled “Resume a previously stopped container”docker start pcore-1Remove a container after use
Section titled “Remove a container after use”docker rm pcore-1List all instantiated containers
Section titled “List all instantiated containers”docker ps -aStart multiple containers
Section titled “Start multiple containers”Terminal 1:
docker run --name pentest1 -ti parrotsec/securityTerminal 2: ```bash docker run –name pentest2 -ti parrotsec/security
**Terminal 3:** ```bashdocker run --name msf-listener -ti parrotsec/metasploitRemove all containers
Section titled “Remove all containers”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”docker run --rm -ti parrotsec/coreUse Volumes to share files with the host
Section titled “Use Volumes to share files with the host”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.
docker run --rm -ti -v $PWD/work:/work parrotsec/coreUse Volumes to share files across multiple containers
Section titled “Use Volumes to share files across multiple containers”Terminal 1:
docker run --name pentest -ti -v $PWD/work:/work parrotsec/securityTerminal 2: ```bash docker run –rm –network host -v $PWD/work:/work -ti parrotsec/security
**Terminal 3:** ```bashdocker run --rm -v $PWD/work:/work -ti parrotsec/metasploitNetworking
Section titled “Networking”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:
docker run --rm -p 8080:80 -ti parrotsec/coreNote 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:
-p <host port>:<container port> (e.g. -p 8080:80)-p <host port>:<container port>/<protocol> (e.g. -p 8080:80/tcp)In case of multiple addresses on the host network:
-p <address>:<host port>:<container port> (e.g. -p 192.168.1.30:8080:80)Use network host instead of Docker NAT
Section titled “Use network host instead of Docker NAT”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:
docker run --rm --network host -ti parrotsec/core