├── cpu-opt └── Dockerfile ├── LICENSE └── README.md /cpu-opt/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | 3 | WORKDIR /root/ 4 | 5 | RUN apt-get update && apt-get -qy install \ 6 | automake \ 7 | build-essential \ 8 | libcurl4-openssl-dev \ 9 | libssl-dev \ 10 | git \ 11 | ca-certificates \ 12 | libjansson-dev libgmp-dev g++ --no-install-recommends 13 | 14 | 15 | RUN git clone --recursive https://github.com/JayDDee/cpuminer-opt cpuminer-multi 16 | WORKDIR /root/cpuminer-multi 17 | 18 | RUN ./autogen.sh 19 | RUN CFLAGS="-O3 -march=native -Wall" CXXFLAGS="$CFLAGS -std=gnu++11" ./configure --with-curl 20 | 21 | RUN make 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Alex Ellis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | mine-with-docker 2 | ================= 3 | 4 | This repository contains Docker images and Dockerfiles that let you get from zero to mining in around 5 minutes on any Linux host anywhere. 5 | 6 | CPU mining can be profitable using algorithmns like: Cryptonight, Hodl or Equihash. Find out more about [profitability here](https://www.nicehash.com/profitability-calculator). 7 | 8 | Disclaimer: this software is provided with no warranty. Use at your own risk. If you plan to mine on a cloud check the terms and conditions before you start. The same applies if you are using private equipment or an on-site datacenter for mining. 9 | 10 | > Tip: Mining will use all the CPU resources available on the machine so do not run it where you have critical applications. 11 | 12 | ## How does it work? 13 | 14 | Instead of mining BitCoin or other currencies on your own this software works by connecting your CPU / GPU to a mining pool. You get paid for the shares your computer makes towards solving a block. The NiceHash mining pool used in this example lets you mine using two dozen different algorithms and can tell you what is most profitable for your hardware. 15 | 16 | * What should I mine? 17 | 18 | At time of writing a quad-core Intel CPU would be best mining Cryptonight, Hodl or Equihash. 19 | 20 | * How do I get a wallet? 21 | 22 | You can sign-up for a wallet at [blockchain.info](https://blockchain.info) or [coinbase.com](https://www.coinbase.com/). When you create a wallet you can then click "receive funds" or similar to generate a new address for the wallet. 23 | 24 | * What is the barrier to entry? 25 | 26 | There barrier to entry is super low - you just have to have a Linux system connected to the Internet where you can install Docker. That's it. You then run the image I've already built and start accruing Bitcoins. 27 | 28 | * Can I use my Raspberry Pi cluster? 29 | 30 | Absolutely not.. there is no point even going there and believe me I've tried. You may find an obscure "alt coin" that can be mined with a Raspberry Pi but getting the money out of an obscure mining pool or exchange is more trouble than it's worth. 31 | 32 | * Is it profitable? 33 | 34 | It can be profitable depending on your hardware and electricity costs. If you have a single node and can get paid 2-5USD / day for instance then that's going to equate to 60-150 USD / month. Now if you actually have 20 or 50 nodes you can apply a multiplier. 35 | 36 | * Where have you tested this? 37 | 38 | Tested on cloud, but as I mentioned - check T&Cs before starting. You take full responsibility for any breach of T&Cs. 39 | 40 | Own hardware: 41 | 42 | - MacBook Pro 13" touchbar i5 43 | - Intel Nuc i5 Gen 5 44 | - Dell Optiplex Intel i7 45 | 46 | * What is Docker? 47 | 48 | Docker uses containers and immutable images to build and package software and all its dependencies. [Read more here](https://www.docker.com/what-docker) 49 | 50 | Try my [Hands-On Labs for Docker](https://github.com/alexellis/HandsOnDocker/blob/master/Labs.md) if you want to learn more. 51 | 52 | > Tip: If you have credits with a cloud provider or are using the Spot Instance market then this could be a way for you to generate some coin at a low cost. 53 | 54 | ## Pre-reqs 55 | 56 | We need to install Docker CE so that we can run a container. The container holds all the mining code and dependencies as a single immutable image. You can install with a single line using a utility script - I generally use this with Ubuntu, but [other distributions are supported too](https://www.docker.com/community-edition). 57 | 58 | * Install Docker CE: 59 | 60 | ``` 61 | curl -sL https://get.docker.com | sh 62 | ``` 63 | 64 | > If not running as a root user then you should look at the final message about using `usermod` to grant access to Docker to your user account. This may be something like `usermod alexellis -aG docker` 65 | 66 | * Setup Docker Swarm 67 | 68 | We will be using Docker Swarm to control the container we're using for mining. 69 | 70 | Type in the following: 71 | 72 | ``` 73 | docker swarm init 74 | ``` 75 | 76 | > If this command complains about `--advertise-addr` - then pass `--advertise-addr=127.0.0.1`. 77 | 78 | ## Start mining 79 | 80 | Create a service and enter your bitcoin wallet ID: 81 | 82 | * Mine Hodl 83 | 84 | ``` 85 | docker service create --mode=global \ 86 | --name miner alexellis2/cpu-opt:2018-1-2 ./cpuminer \ 87 | -a hodl \ 88 | -o stratum+tcp://hodl.usa.nicehash.com:3352 \ 89 | -u 1M2KME8VBx24RsU3Ed2dEkF9EFghn3jR2o.cloud1 90 | ``` 91 | 92 | * Mine Cryptonight 93 | 94 | ``` 95 | docker service create --mode=global \ 96 | --name miner alexellis2/cpu-opt:2018-1-2 ./cpuminer \ 97 | -a cryptonight \ 98 | -o stratum+tcp://cryptonight.usa.nicehash.com:3355 \ 99 | -u 1M2KME8VBx24RsU3Ed2dEkF9EFghn3jR2o.cloud1 100 | ``` 101 | 102 | **You must replace "usa" with your location such as "hk" or "eu", read on.** 103 | 104 | > Tip : If you are planning on using an Atom processor you will need to rebuild the image using the instructions below. Atom CPUs are not advised for mining. 105 | 106 | * Replace "1M2KME8VBx24RsU3Ed2dEkF9EFghn3jR2o" with your wallet ID and "cloud1" with the name of the host you're mining on if you want to track it. 107 | 108 | * If you live outside the EU then find your [nearest Stratum proxy server from Nicehash](https://www.nicehash.com/asic-mining) and replace the `eu` URL with your nearest location. 109 | 110 | * If you're running the command for the second time then remove the service with: `docker service rm miner` 111 | 112 | ## Limiting CPU usage 113 | 114 | This is a community suggestion from @linuxjuggler. 115 | 116 | 117 | If you want you can limit the CPU usage using the `--limit-cpu` option in the `docker service create` command. 118 | 119 | Also its worth mentionining that you can limit the CPU core usage by selecting which cores to target via 120 | 121 | ``` 122 | docker run alexellis2/cpu-opt:2018-1-2 ./cpuminer --help: 123 | --cpu-affinity set process affinity to cpu core(s), mask 0x3 for cores 0 and 1 124 | --cpu-priority set process priority (default: 0 idle, 2 normal to 5 highest) 125 | ``` 126 | 127 | @linuxjuggler writes: 128 | 129 | > Limiting the amount of CPU or number of cores being used may mean you can continue to use the system for other purposes. It is also less likely to trigger a high CPU alert if you are running monitoring software. 130 | 131 | ## Stop/pause mining 132 | 133 | To pause mining type in `docker service scale miner=0`. To resume set the replicas to `1`. 134 | 135 | To completely stop mining use `docker service rm miner` 136 | 137 | ## Rebuild the image 138 | 139 | This is optional and not recommended for beginners. 140 | 141 | If you need to rebuild the Docker image for updates or for a different CPU architecture/variation such as an Atom CPU: 142 | 143 | ``` 144 | git clone https://github.com/alexellis/mine-with-docker 145 | cd mine-with-docker/cpu-opt 146 | docker build -t cpu-opt:latest . 147 | ``` 148 | 149 | After rebuilding the image swap out `alexellis2/cpu-opt:2018-1-2` for `cpu-opt:latest` or whatever you chose to call it in the `docker build` command. 150 | 151 | ## Monitor your balance / workers 152 | 153 | You can use the nicehash UI to monitor your balance and predicted payout. Mining pools generally wait until you reach a certain (low) balance before sending an automatic transfer to your wallet. 154 | 155 | Here's an example with my donation address: 156 | 157 | ``` 158 | https://www.nicehash.com/miner/1M2KME8VBx24RsU3Ed2dEkF9EFghn3jR2o 159 | ``` 160 | 161 | Nicehash and many other mining pools have [their own HTTP APIs](https://www.nicehash.com/doc-api) where you can programatically query your hashing rate, balance and list of connected workers. 162 | 163 | > Tip: You can use different mining pools simply by adjusting the stratum URL passed in via the `-o` flag to the container. 164 | 165 | 166 | ## Donate 167 | 168 | You can follow me on Twitter [@alexellisuk](https://twitter.com/alexellisuk) or make a donation with Bitcoin or Ethereum below: 169 | 170 | Donate via: 171 | 172 | * BTC: 1M2KME8VBx24RsU3Ed2dEkF9EFghn3jR2o 173 | * Bitcoin Cash: 1M2KME8VBx24RsU3Ed2dEkF9EFghn3jR2o 174 | * ETH: 0x0D0c7108AD4180486E03B4Fc44AD794a209eCb37 175 | * LTC: LTt4VGXJMXALgzyjw6zACRxigNADaDYNH9 176 | 177 | ## License 178 | 179 | MIT 180 | 181 | Copyright Alex Ellis 2017-2018 182 | --------------------------------------------------------------------------------