Browse Source

add dockerfile and description about docker in README.md

pull/8/head
markuman 7 years ago
parent
commit
1c4abd369e
  1. 24
      README.md
  2. 3
      docker-entrypoint.sh
  3. 22
      dockerfile

24
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
```

3
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

22
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"]
Loading…
Cancel
Save