Skip to content

Commit d8f99f0

Browse files
authored
Merge pull request #50 from w3tecch/feature/docker-image
Feature/docker image
2 parents 488fed9 + 66a69a7 commit d8f99f0

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

. dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.vscode
2+
node_modules
3+
test
4+
.editorconfig
5+
.env.example
6+
.gitignore
7+
.travis.yml
8+
appveyor.yml
9+
icon.png
10+
LICENSE
11+
README.md

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:alpine
2+
3+
# Create work directory
4+
WORKDIR /usr/src/app
5+
6+
# Install runtime dependencies
7+
RUN npm install yarn -g
8+
9+
# Copy app source to work directory
10+
COPY . /usr/src/app
11+
12+
# Install app dependencies
13+
RUN yarn install
14+
15+
# Build and run the app
16+
CMD npm start serve

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,85 @@ The last step is the easiest, just hit the following command in your terminal, b
371371
npm start db.seed
372372
```
373373
374+
## Run in Docker container
375+
376+
### Install Docker
377+
378+
Before you start, make sure you have a recent version of [Docker](https://docs.docker.com/engine/installation/) installed
379+
380+
### Build Docker image
381+
382+
```shell
383+
docker build -t <your-image-name> .
384+
```
385+
386+
### Run Docker image in container and map port
387+
388+
The port which runs your application inside Docker container is either configured as `PORT` property in your `.env` configuration file or passed to Docker container via environment variable `PORT`. Default port is `3000`.
389+
390+
#### Run image in detached mode
391+
392+
```shell
393+
docker run -d -p <port-on-host>:<port-inside-docker-container> <your-image-name>
394+
```
395+
396+
#### Run image in foreground mode
397+
398+
```shell
399+
docker run -i -t -p <port-on-host>:<port-inside-docker-container> <your-image-name>
400+
```
401+
402+
### Stop Docker container
403+
404+
#### Detached mode
405+
406+
```shell
407+
docker stop <container-id>
408+
```
409+
410+
You can get a list of all running Docker container and its ids by following command
411+
412+
```shell
413+
docker images
414+
```
415+
416+
#### Foreground mode
417+
418+
Go to console and press <CTRL> + C at any time.
419+
420+
### Docker environment variables
421+
422+
There are several options to configure your app inside a Docker container
423+
424+
#### project .env file
425+
426+
You can use `.env` file in project root folder which will be copied inside Docker image. If you want to change a property inside `.env` you have to rebuild your Docker image.
427+
428+
#### run options
429+
430+
You can also change app configuration by passing environment variables via `docker run` option `-e` or `--env`.
431+
432+
```shell
433+
docker run --env DB_HOST=localhost -e DB_PORT=3306
434+
```
435+
436+
#### environment file
437+
438+
Last but not least you can pass a config file to `docker run`.
439+
440+
```shell
441+
docker run --env-file ./env.list
442+
```
443+
444+
`env.list` example:
445+
446+
```
447+
# this is a comment
448+
DB_TYPE=mysql
449+
DB_HOST=localhost
450+
DB_PORT=3306
451+
```
452+
374453
## Further Documentations
375454
376455
| Name & Link | Description |

0 commit comments

Comments
 (0)