More Docker Tricks

Mounting External Folder

If you are new to Docker and trying MagicMirror with the Docker container, you might be wondering how you can send and retrieve files from a Docker container, so that you can use the MagicMirror Docker container on your own contracts, and save the outputs in locations you want.

For that, we use the -v mounting volume option when we start the MagicMirror Docker container. Assume you have a folder ./myfolder/ on your own system with the following layout.

.└── myfolder/
     ├── result/
     └── contracts/
         ├── a.sol        
         └── b.sol

Let's say you want the container to be able to read the contract files in ./myfolder/contracts/ and outputs the result in ./myfolder/result/. You can execute the following command to launch the container with ./myfolder/ mounted to /home/mount/ in the container.

*Note, /home/ is where the magic_mirror executable is at.

docker run -it -w /home -v ./myfolder:/home/mount magicmirrorfuzzing/magic_mirror

Once you execute the above command, you will find that the /home/mount/ directory is created in the Docker container, and both your system and container can read and write into the directory.

Next, you can execute the following command in the container to fuzz a.solwith the --output_dir option in magic_mirror, so the outputs from MagicMirror will be saved in the result folder of your own.

./magic_mirror single-file-mode --contract_dir ./mount/contracts/a.sol --output_dir ./mount/result

You will then see the outputs showing up on your own system in the ./myfolder/result/a.sol/ directory.

One Command That Does It All

In the above instructions, you still need two commands to do what you want, however, there's a better way, a single command that does it all:

  1. Launch the container

  2. Mount the folder

  3. Fuzz your contract(s), output results in your mounted folder

  4. Terminate and delete the container instance

Copy, paste, update the following command and you are on your way to a simpler life.

docker run --rm -it -w /home -v ./myfolder:/home/mount magicmirrorfuzzing/magic_mirror ./magic_mirror single-file-mode --contract_dir ./mount/contracts/a.sol --output_dir ./mount/result 

And here is an explanation of how this command is constructed.

Last updated