Better Dockerfile

master
joenas 2017-09-12 12:53:18 +02:00
parent b80b957504
commit 3cc2970cba
4 changed files with 74 additions and 8 deletions

View File

@ -1,5 +1,6 @@
.git
.gitignore
README.md
docker-compose.yml
node_modules
docker-compose.yaml
node_modules/
config/

2
.gitignore vendored
View File

@ -4,3 +4,5 @@ minetest-registration.yaml
logs
*.log
node_modules
docker-compose.yaml
docker-compose.yml

View File

@ -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"]

View File

@ -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!