diff --git a/README.md b/README.md index 344da323fa..bb35684634 100644 --- a/README.md +++ b/README.md @@ -353,4 +353,28 @@ http://localhost:3000/download?name=fileName ``` +# Docker +Simply build with `docker build -t xmysql .` and run with `docker run -p 3000:3000 -d xmysql` + +The best way for testing is to run mysql in a docker container too and create a docker network, so that `xmysql` can access the `mysql` container with a name from docker network. + +1. Create network + * `docker network create mynet` +2. Start mysql with docker name `some-mysql` and bind to docker network `mynet` + * `docker run --name some-mysql -p 3306:3306 --net mynet -e MYSQL_ROOT_PASSWORD=password -d mysql` +3. build xmysql container (if not done yet) + * `docker build -t xmysql .` +4. run xmysql and set env variable for `some-mysql` from step 2 + * `docker run -p 3000:3000 -d -e DATABASE_HOST=some-mysql --net mynet xmysql` + +You can also pass the environment variables to a file and use them as an option with docker like `docker run --env-file ./env.list -p 3000:3000 --net mynet -d xmysql` + +environment variables which can be used: + +``` +ENV DATABASE_HOST 127.0.0.1 +ENV DATABASE_USER root +ENV DATABASE_PASSWORD password +ENV DATABASE_NAME sakila +``` \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000000..84a52ca79f --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cd /usr/src/app/ +node index.js -h $DATABASE_HOST -p $DATABASE_PASSWORD -d $DATABASE_NAME -u $DATABASE_USER \ No newline at end of file diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000000..3ca6834bea --- /dev/null +++ b/dockerfile @@ -0,0 +1,22 @@ +FROM mhart/alpine-node:latest + +RUN mkdir -p /usr/src/{app,bin,lib} +WORKDIR /usr/src/app + +# only install production deps to keep image small +COPY package.json /usr/src/app +RUN npm install --production + +COPY index.js /usr/src/app +COPY bin/ /usr/src/app/bin +COPY lib/ /usr/src/app/lib +COPY docker-entrypoint.sh /docker-entrypoint.sh + +# env +ENV DATABASE_HOST 127.0.0.1 +ENV DATABASE_USER root +ENV DATABASE_PASSWORD password +ENV DATABASE_NAME sakila + +EXPOSE 3000 +ENTRYPOINT ["/docker-entrypoint.sh"]