Giter VIP home page Giter VIP logo

node-docker-microservice's Introduction

node-docker-microservice

Learn Docker by building a Microservice!

This is a companion project to my article on 'Learn Docker by building a Microservice' demonstrating key concepts of Docker using a Node.js microservice as an example.

Pre-requisites

You must have Docker installed for this code to work! Check the Installation Guide if you haven't got it installed.

Coding

To start or stop the test database, build the test-database image and run it:

cd ./test-database
docker build -t test-database .
docker run -it -p 3306:3306 test-database

Some commands for working with the test server:

cd ./users-service
npm install         # setup everything
npm test 			# unit test - no need for a test database running
npm start           # run the server - you must have a test database running
npm run debug       # run the server in debug mode, opens a browser with the inspector
npm run lint        # check to see if the code is beautiful

You can also run the test server in its own container:

docker build -t users-service .
docker run -it -p 8123:8123 --link db:db -e DATABASE_HOST=DB users-service

Integration Testing

To test the entire stack, run:

docker-compose build
docker-compose up -d
sleep 10 # give the database server enough time to start!
cd integration-test && npm install && npm start && cd ..
docker-compose down

node-docker-microservice's People

Contributors

dwmkerr avatar edwastone avatar pcanterini avatar sagitsofan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-docker-microservice's Issues

Step 3: Linking Containers ... Not clear you are meant to stop the old users-service

Hey

This is for your blog entry: http://www.dwmkerr.com/learn-docker-by-building-a-microservice/

In step 3: Linking Container with the 'link' parameter, I had both containers running when I tried to run the following docker run -it -p 8123:8123 --link db:db -e DATABASE_HOST=DB users-service.

My understanding was it would connect two currently running containers, not a one currently running to a new one. The error message wasn't helpful at all either.

It would had been clearer to me if you specifically state you have to stop the users-service container before running this command.

Cheers

Step 4 doesn't work `Error: Cannot enqueue Query after fatal error.`

Hi

Really good tutorial, but sadly I can't get the final step with docker-composer to work.

I've also tried pulling your repo and running that but I seem to get the same error from the users-service

Error: An error occured getting the users: Error: Cannot enqueue Query after fatal error.

It works if I run each container separately.

I also ran into this issue in step 2 if it matters: #4 . I don't know how to fix it in docker-file though as I don't know where to put the sleep

Any help would be fantastic.

Cheers

I'm on a macbook air using Docker for Mac

-d option on docker-compose

I don't have the -d option on docker-compose in my Mac Docker Quickstart Terminal for some reason? Thanks!

[Blog] Use long options in examples

Thanks for this write up, I am enjoying going through it!

Since this is a post that is intended to teach may I suggest you use long options instead of short options. This would also save some explaining on what the short options are. It is self documenting to use long options (most of the time).

e.g.

docker run --name db -e MYSQL_ROOT_PASSWORD=123 -p 3306:3306 mysql:latest  
docker run --name db --env=[MYSQL_ROOT_PASSWORD=123] --publish=3306:3306 mysql:latest  

Also, step #3 for the command above discusses the --detach command but it isn't in the example.

Step 4: Integration Testing the Environment requires user to run `docker rm db` first

This is for your blog entry http://www.dwmkerr.com/learn-docker-by-building-a-microservice/

I was following the tutorial but ran into a bug for step 4 when running the command docker run --name db test-database

I received a docker: Error response from daemon: Conflict. The name "/db" is already ...

Running docker rm db first fixed this issue. Perhaps add a note to step 4?

Step 1: ERROR 1045 (28000): Access denied for user 'users_service'@'localhost'

I did git clone.
I did git checkout step1.
I did ./start.sh.

The following was displayed.

Starting DB...
2cc0806676b0b73021429f7c57b6186f2437bc9203048729208d95b9efa7705c
Waiting for DB to start up...
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Got error: Access denied for user 'users_service'@'localhost' (using password: YES)
Setting up initial data...
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'users_service'@'localhost' (using password: YES)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.