10-04-22 | Megan Ryder
1: With a NiceHash account and Docker installed, we're ready to start mining.
docker service create --name miner
alexellis2/cpu-opt:2018-1-2 ./cpuminer
-a cryptonight
-o stratum+tcp://cryptonight.usa.nicehash.com:3355
-u 3HSFKUagtL5Z6KFE7gAJ3i9YgWkmaKH6Zb.miner1
This command will create a docker service called miner that will start CPU mining. You'll need to substitute 3HSFKUagtL5Z6KFE7gAJ3i9YgWkmaKH6Zb with the address generated when you created your NiceHash account. And you can replace miner1 with the name of the host, if you want to track it.
2: Helper functions to start and stop mining
If you're like me and you just want to mess around with this on your primary laptop, you'll probably not want to run the miner 100% of the time. I've create a few helper functions to start and stop mining.
First, create a file called start-mining and place it in /usr/local/bin or some other directory in your PATH:
#!/bin/bash
docker service ps miner >/dev/null 2>&1
if [[ $? -eq 1 ]]; then
docker service create
--name miner
alexellis2/cpu-opt:2018-1-2
./cpuminer
-a cryptonight
-o stratum+tcp://cryptonight.usa.nicehash.com:3355
-u 3HSFKUagtL5Z6KFE7gAJ3i9YgWkmaKH6Zb.miner1
else
docker service scale miner=1
fi
docker service logs -f miner
And create an accompanying file called stop-mining.
#!/bin/bash
docker service scale miner=0
Now we'll make these files executable:
chmod +x /usr/local/bin/start-mining
chmod +x /usr/local/bin/stop-mining
The start-mining script creates the miner service if it does not yet exist and ensures the service has one worker if it exists. It's counterpart, stop-mining, simply scales the worker to zero.
If you need to remove the service completely, you can run:
docker service rm miner
<