Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q: Docker #1

Open
bradschafer opened this issue Sep 13, 2018 · 7 comments
Open

Q: Docker #1

bradschafer opened this issue Sep 13, 2018 · 7 comments

Comments

@bradschafer
Copy link

I am working my way through this wonderful repo, however, I am unable to get the API docker-compose running. I've been digging through it some and it seems to be that the MongoDB connection fails, so the API server fails. I've been seeing if I can get it to restart on fail in the compose but no luck so far.

In general I'd really like to get to this point:

  1. A single docker compose file.
  2. A production build of the webclient running in docker with a specific build using something like docker-compose-production.yml
  3. A development build where the mount is running nodemon and running in a docker container.

Basically everything containerized with two 'up' modes dev/prod.

If I make progress, or if you have any hints lets try to post them here, or perhaps I can create a PR.

@walter211
Copy link

seems noboyd maintain this

@jamshally
Copy link
Member

@bradschafer, sorry for the long delay - I just saw this. I have been busy working on V2 of this project, adding many more features including a reusable data-access repository pattern, field and class validation, and full social login. This will include the type of Docker workflow you mention. It should be available in 2 - 4 weeks. However, if you are still wrestling with this, and need for a V1 implementation, LMK and I will take a look at.

@heralight
Copy link

Hi!
Very interested in your v2, Can we have a shoot (beta) on it ?
Thank you very much!

@jamshally
Copy link
Member

@heralight - the master branch is now has the V2 features I described. I still have the following to add:

  • Social login. However, the backend code for Facebook social login is in already in-place, just needs wiring to a UI
  • Full Docker dev/prod mode deployments. I am less experienced with Docker, so might need the help of others to get there. However, the current codebase already leverages docker for the Mongo DB.

@heralight
Copy link

Hello, thank you for reply,

Unfortunately, in the meantime, I left with another open source project… But I will keep an eye on yours.

Anyway, about Docker, I can give some tips relative to your project.

my actual docker usage

_ at root project I have 2 docker-compose, the second extend the first:
docker-compose.yml

version: '3'
services:
  mongo:
    image: mongo:3.6
  authservice:
    build: ./authservice
    ports:
     - "3000:3000"
    env_file:
     - authservice-prod.env
    links:
     - mongo 
    depends_on: 
     - mongo 
    volumes:
     - ./authservice:/starter
     - /starter/node_modules

docker-compose.dev.yml

version: '3'
services:
  mongo:
    image: mongo:3.6
    ports:
     - 27017:27017
  authservice:
    build: ./authservice
    user: root
    command: >
      sh -c "npm install --production &&
             pm2-dev pm2.dev.yml" 
    env_file:
     - authservice-dev.env

And I have a Makefile like:

THIS_FILE := $(lastword $(MAKEFILE_LIST))

test:
		docker-compose up -f test.yml

dev:
		docker-compose -f ./docker-compose.yml  -f ./docker-compose.dev.yml up

dev-mongo:
		docker-compose -f ./docker-compose.yml  -f ./docker-compose.dev.yml run --rm -p 27017:27017 mongo

dev-stop:
		docker-compose -f ./docker-compose.yml  -f ./docker-compose.dev.yml down

dev-auth:
		set -o allexport && source authservice-dev.env && set +o allexport && export MONGODB_URI=mongodb://localhost:27017/micro-auth-dev && cd authservice && npm install --production && npm run dev

build-prod:
		docker-compose build

prod:
		npm build-prod; docker-compose up
install-compose:
		curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` > ~/

docker-compose
		mkdir -p ~/bin/
		mv ~/docker-compose ~/bin/docker-compose
		chown root:root ~/bin/docker-compose
		chmod +x ~/bin/docker-compose

clean-images:
		docker rmi $$(docker images -a --filter=dangling=true -q)

clean-ps:
		docker rm $$(docker ps --filter=status=exited --filter=status=created -q)

clean: clean-images clean-ps


kill-all:
		docker kill $$(docker ps -q)

# be careful, clear all system images
clean-all:
		docker kill $$(docker ps -q)
		docker rm $$(docker ps --filter=status=exited --filter=status=created -q)
		docker rmi $$(docker images -a -q)

Why a docker-compose.dev.yml

To override some values, like which command to run on docker start in dev mode.
For example in production I use in my service docker file:

CMD ["pm2-runtime", "pm2.prod.yml"]

But in dev I want hot reloading, with nom update, all on my local mount point then I override it with

    command: >
      sh -c "npm install --production &&
             pm2-dev pm2.dev.yml" 

You can only mount local volume on dev mode,…etc.
Be careful, docker-compose extend file doesn’t support adding volume part (work in progress on docker-compose project), then as workaround you need to add it in the first one.

In your api/docker-compose.yml
You can remove your command part.
In your api/dockerfile, because docker can reboot your container dynamically depending on its status, no need of nodemon
Prefer
CMD ["npm", "start:prod"]
Instead of
CMD ["npm", "start"]

Prefer
RUN npm install —production
Instead of
RUN npm install

You don’t need to expose port, do it in your docker-compose files only depending on your mode.
e.g.:
No exposure in production exception the final one 80 and 443, your app and mongoldb will be on another subnetwork.
In dev, expose Mongodb and 80, 443

To be full reusable and docker compliant, your application need to recover its configuration from environment variables only and / or a etcd like service, in one word completly stateless.

Best regards,

Alexandre

@recRent
Copy link

recRent commented Nov 21, 2018

I am also following this project & and am interested in learning more about it. Is there a way I can reach out to you to chat about a few of the design decisions I would like to understand better?

@jamshally
Copy link
Member

I am also following this project & and am interested in learning more about it. Is there a way I can reach out to you to chat about a few of the design decisions I would like to understand better?

recRent - would be happy to chat. I'll spin up a separate thread

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants