├── DockerSetup.md ├── README.md ├── gogs ├── README.md └── docker-compose.yml └── mosquitto ├── README.md └── docker-compose.yml /DockerSetup.md: -------------------------------------------------------------------------------- 1 | 2 | # How to get your Mac to talk to docker on QNAP server 3 | 4 | To get your Mac to talk to the QNAP server we can use docker-machine 5 | to manage that connection. That can be very useful if you are already using 6 | docker machine. 7 | 8 | First create the new link with docker machine - and it will be named qnap: 9 | ```bash 10 | docker-machine create --driver=none --url tcp://:2376 qnap 11 | ``` 12 | 13 | Unfortunately, docker-machine does not provide a way to set up the certificates 14 | when using the --none option. So we need to do that by hand. 15 | 16 | Download certs from within the QNAP Container Station in the preferences section. 17 | We will then place them in qnap directory created by docker-machine above: 18 | 19 | ```bash 20 | cd ~/.docker/machine/machines/qnap 21 | cp ~/Downloads/cert/*.pem . 22 | ``` 23 | 24 | You then need to edit the config.json file to be somethng like this (obviously your paths will vary): 25 | ```json 26 | "AuthOptions": { 27 | "CertDir": "/Users/rayj/.docker/machine/machines/qnap/", 28 | "CaCertPath": "/Users/rayj/.docker/machine/machines/qnap/ca.pem", 29 | "CaPrivateKeyPath": "/Users/rayj/.docker/machine/machines/qnap/key.pem", 30 | "CaCertRemotePath": "", 31 | "ServerCertPath": "/Users/rayj/.docker/machine/machines/qnap/cert.pem", 32 | "ServerKeyPath": "/Users/rayj/.docker/machine/machines/qnap/key.pem", 33 | "ClientKeyPath": "/Users/rayj/.docker/machine/machines/qnap/key.pem", 34 | "ServerCertRemotePath": "", 35 | "ServerKeyRemotePath": "", 36 | "ClientCertPath": "/Users/rayj/.docker/machine/machines/qnap/cert.pem", 37 | "ServerCertSANs": [], 38 | "StorePath": "/Users/rayj/.docker/machine/machines/qnap" 39 | } 40 | ``` 41 | 42 | You can test by doing something like this: 43 | ```bash 44 | $> docker-machine ls --filter name=qnap 45 | ``` 46 | 47 | Then to use this machine do: 48 | ```bash 49 | $> eval `docker-machine env qnap` 50 | ``` 51 | 52 | Then do normal docker commands like: 53 | ```bash 54 | $> docker ps 55 | ``` 56 | 57 | You may have a newer version of docker running on your developer machine. If that happens 58 | you will get a message something like this: 59 | **Error response from daemon: client is newer than server (client API version: 1.24, server API version: 1.23)** 60 | 61 | You can set an environment variable to make Docker happy: 62 | export DOCKER_API_VERSION=1.23 63 | 64 | (If using docker-compose you may also want to set COMPOSE_API_VERSION as well.) 65 | 66 | It is really a shame docker-machine can not set the DOCKER_API_VERSION for us! 67 | 68 | ### Problem with Docker for Mac 69 | 70 | Unfortunately, it appears that Docker for Mac version 17.09.0-ce has a bug and it does not 71 | honor the DOCKER_API_VERSION environment variable. 72 | 73 | I was able to work around this by using docker version manager (dvm): 74 | https://howtowhale.github.io/dvm/ 75 | 76 | You can install this on a Mac using brew: 77 | ```bash 78 | brew install dvm 79 | dvm use 17.05.0-ce 80 | ``` 81 | 82 | I use version 17.05.0-ce of docker which properly honors DOCKER_API_VERSION 83 | 84 | 85 | After all that you should be able use your docker client to talk to the engine on your qnap 86 | server just fine! 87 | 88 | ### Bash functions to make life easier 89 | 90 | Unfortunately, things are still a little cumbersome - you have to call docker-machine, set 91 | one or two environment variables, and call dvm. Ug! To make my life a little simpler I added the following to my .bash_profile 92 | 93 | ```bash 94 | function setTerm() { PROFILE=${1}; echo "tell app \"Terminal\" to set current settings of first window to settings set \"${PROFILE}\""|osascript; }; 95 | 96 | setQnap() { 97 | eval $(docker-machine env qnap) 98 | export DOCKER_API_VERSION=1.23 99 | export COMPOSE_API_VERSION=1.23 100 | dvm use 17.05.0-ce 101 | setTerm homebrew 102 | } 103 | 104 | unsetQnap() { 105 | eval $(docker-machine env -u) 106 | unset DOCKER_API_VERSION 107 | unset COMPOSE_API_VERSION 108 | dvm deactivate 109 | setTerm basic 110 | } 111 | ``` 112 | 113 | Then I just call setQnap or unsetQnap to switch between talking to the qnap docker 114 | engine or the one om my laptop. (The setTerm stuff is specific to Mac terminal and can 115 | be removed.) 116 | 117 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Docker on QNAP 3 | 4 | The QNAP storage server comes with a system called container-station 5 | which is really just a fancy UI over docker. 6 | 7 | In this repository I have some of the docker compose files I have created 8 | to get the most out of my QNAP server. 9 | 10 | First you will want to set up your machine to point to the docker instance 11 | running on QNAP. Here are some instructions: [DockerSetup.md](DockerSetup.md) 12 | 13 | ### Applications 14 | 15 | Gogs - Container-Station has a way to load GitLab which is a Git 16 | repository. Useful for local development and code you do not want 17 | to exist on GitHub. However, Gitlab is bloated! It consumed 25% 18 | of the memory on QNAP server when I installed it. Gogs is much lighter 19 | weight and by using sqllite as a database it only requires 1 container 20 | to run. The result is that it only used 1% of QNAPs memory. It may not 21 | have some of the features of GitLab but it is perfect for home needs. 22 | 23 | 24 | -------------------------------------------------------------------------------- /gogs/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Gogs 3 | 4 | [Gogs](https://gogs.io) is an open source git repository server that is very lightweight. 5 | 6 | QNAP's Container-Station shows GitLab as one of the easy to install containers. However, 7 | GitLab is a bit of a pig. It consumed 25-30% of the memory on my QNAP server. It launches 8 | 3 different containers including postgress and redis. Gogs on the other hand needs no 9 | other containers (if you use sqllite) and consumes about 1% of the QNAP memory. If you 10 | are going to install a local git repository on your QNAP server I highly recommend Gogs. 11 | (Despite the very weird name!) 12 | 13 | Thankfully getting Gogs to run on QNAP is trivial. They have a [version](https://github.com/gogits/gogs/tree/master/docker) built in Docker that makes set-up very easy. 14 | 15 | The file **docker-compose.yml** will easily get you going. 16 | 17 | Before running though you should consider what ports you want the server to run on. The 18 | included compose file maps these to 10022 for ssh and 10080 for http. You may need to 19 | edit the compose file if you are already using those ports on your QNAP server. 20 | 21 | To get things running simply do: 22 | ```bash 23 | docker-compose up -d 24 | ``` 25 | 26 | You will then need to go to :10080 to finish the configuration. I just 27 | configured the server to use sqllite since this repository is not going to be heavily used. 28 | 29 | All data will be stored in the named volume: _gogs_data_ 30 | 31 | If you ssh to you QNAP box you should be able to find it here: 32 | ```bash 33 | /share/Container/container-station-data/lib/docker/volumes/gogs_data/_data 34 | ``` 35 | 36 | This can be useful if you need to edit the ini file by hand in gogs/conf/app.ini 37 | -------------------------------------------------------------------------------- /gogs/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.2' 2 | services: 3 | gogs: 4 | image: gogs/gogs 5 | container_name: gogs 6 | restart: always 7 | volumes: 8 | - data:/data 9 | ports: 10 | - "10022:22" 11 | - "10080:3000" 12 | 13 | volumes: 14 | data: 15 | 16 | 17 | -------------------------------------------------------------------------------- /mosquitto/README.md: -------------------------------------------------------------------------------- 1 | # Mosquitto 2 | 3 | [Mosquitto](https://mosquitto.org) is an open source message broker often used in the world of IOT. 4 | 5 | I wanted to play with it for some home-automation stuff. Again - make sure you have done the [Docker Setup](../DockerSetup.md). The file **docker-compose.yml** will easily get you going. 6 | 7 | This compose file created a named volume called *mosquitto_data*. You will want to ssh into your QNAP box to adjust some of the settings. 8 | 9 | ```bash 10 | vi /share/Container/container-station-data/lib/docker/volumes/mosquitto_data/_data/config/mosquitto.conf 11 | ``` 12 | 13 | Check out the man page for how to configure mosquitto [here](http://mosquitto.org/man/mosquitto-conf-5.html). Here is a smple to get you going. 14 | 15 | ```ini 16 | # mqtt configuration file 17 | # See http://mosquitto.org/man/mosquitto-conf-5.html 18 | persistence true 19 | persistence_location /mosquitto/data/ 20 | log_dest file /mosquitto/log/mosquitto.log 21 | ``` 22 | 23 | 24 | ### Security 25 | 26 | You really should lock the thing down at least a little. You can add a basic password file to help a little. Though you really should set up TLS to ensure real security. 27 | 28 | You may not have the utility command-line tools for Mosquitto installed. but don't worry they are in the docker container you are using! The following command will create a new password file. 29 | 30 | ```bash 31 | # Create a password file 32 | docker run --rm -it -w /mosquitto/config -v mosquitto_data:/mosquitto eclipse-mosquitto mosquitto_passwd -c passwords.txt 33 | ``` 34 | 35 | When you run this it then requires you to enter the password via stdin twice. However, there was something weird running from docker because the prompt for the password came after I hit enter! 36 | 37 | As you add more it is a little easier to use the -b (batch mode) where you can pass the username and password on the command line. 38 | 39 | ```bash 40 | docker run --rm -it -w /mosquitto/config -v mosquitto_data:/mosquitto eclipse-mosquitto mosquitto_passwd -b passwords.txt bobby bobbypassword 41 | ``` -------------------------------------------------------------------------------- /mosquitto/docker-compose.yml: -------------------------------------------------------------------------------- 1 | # mosquitto set up 2 | version: '2.0' 3 | 4 | services: 5 | openhab: 6 | image: "eclipse-mosquitto" 7 | container_name: mqtt 8 | restart: always 9 | ports: 10 | - "1883:1883" 11 | - "9001:9001" 12 | volumes: 13 | - data:/mosquitto 14 | 15 | volumes: 16 | data: 17 | --------------------------------------------------------------------------------