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