diff --git a/.dockerignore b/.dockerignore index d1eaa0b..d43ea5f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,6 @@ .git .gitignore README.md -docker-compose.yml -node_modules +docker-compose.yaml +node_modules/ +config/ diff --git a/.gitignore b/.gitignore index e3eff46..f926d25 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ minetest-registration.yaml logs *.log node_modules +docker-compose.yaml +docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 1756079..a7b10cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,18 @@ FROM node:8.4.0 -RUN mkdir /src +RUN mkdir /app +WORKDIR /app -WORKDIR /src -ADD package.json /src/package.json -RUN npm install +# See http://jdlm.info/articles/2016/03/06/lessons-building-node-app-docker.html +# and https://github.com/dockersamples/example-voting-app/blob/7629961971ab5ca9fdfeadff52e7127bd73684a5/result-app/Dockerfile#L8 + +ADD package.json /app/package.json +RUN npm install && npm ls +RUN mv /app/node_modules /node_modules + +ADD . /app EXPOSE 9000 -EXPOSE 9898 -CMD node app.js -p 9000 -c config/config.yaml +ENTRYPOINT ["node", "app.js"] +CMD ["-p", "9000", "-c", "config/config.yaml"] diff --git a/README.md b/README.md index bf1582c..ca5bfc6 100644 --- a/README.md +++ b/README.md @@ -26,3 +26,60 @@ $ node app.js -p 9000 -c config/config.yaml # Restart your HS ``` + +# Running with Docker + +You need to generate the registration file and let synapse (or whatever server you're using) have access to it. The approach here is to generate it with a temporary container and a [bind mount](https://docs.docker.com/engine/admin/volumes/bind-mounts/) so the file is accessible on the host and can be copied to the homeserver. + +Below are a few example of how do achieve this. + + +### Build the image +``` +# Feel free to change the tag +docker build -t matrix-minetest-image . +``` + +### Generating registration file +``` +# The host in the URL depends on what you later name the container +docker run --rm -v "$(pwd)":/app matrix-minetest-image \ + -r -u "http://matrixminetest:9000" -c config/config.yaml +cp minetest-registration.yaml /path/to/synapse/ +``` + +All the arguments after the image name (`matrix-minetest-image`) will be passed to `node`, so you can use another config file if you wish. + + +### Running the container with default arguments + +``` +# Port is 9000 and config is config/config.yaml as per the Dockerfile CMD +docker run -p 4501:4501 -d --name matrixminetest -v $(pwd):/app/ matrix-minetest-image +``` + +### Running the container with custom arguments + +``` +# Using 127.0.0.1 means the port won't be exposed outside the host, so you'd have to reverse proxy it +docker run -p 127.0.0.1:4501:4501 -d --name matrixminetest -v $(pwd):/app/ matrix-minetest-image \ + -p 9001 -c config/other_config.yaml +``` + +### Update config.yaml +If you want to use the internal network you need to set the URL to synapse to the name of the container. + +``` +homeserver: + # The domain for the client-server API calls. + url: "http://synapse:8008" +``` + +### Creating a network to connect the containers +``` +docker network create matrix-network +docker network connect matrix-network [your_synapse_container] +docker network connect matrix-network matrixminetest +``` + +Now restart your containers and you should be good to go!