Skip to content

Instantly share code, notes, and snippets.

@visualjeff
Created April 13, 2017 05:53
Show Gist options
  • Save visualjeff/796f9b49d1b3ec633f794df719e6e1c6 to your computer and use it in GitHub Desktop.
Save visualjeff/796f9b49d1b3ec633f794df719e6e1c6 to your computer and use it in GitHub Desktop.
How to Dockerize your new scimgateway project
# To build: docker build --force-rm=true -t scimgateway-data:latest .
# To run: docker run -d --name scimgateway-data -t scimgateway-data:latest
FROM busybox:latest
MAINTAINER Jeffrey Gilbert
RUN mkdir -p /home/scimgateway/config
VOLUME /home/scimgateway/config
CMD ["echo", "Data container for scimgateway created and will now shutdown. No need to run again."]
version: '2'
services:
scimgateway:
build:
context: .
dockerfile: Dockerfile
image: scimgateway:latest
container_name: scimgateway
hostname:
scimgateway
volumes:
- /home/scimgateway/config:/home/scimgateway/config:rw
volumes_from:
- scimgateway-data
ports:
- "8880:8880"
environment:
- ENVIRONMENT=development
- PORT=8880
- SEED=localhost
restart: on-failure:3
scimgateway-data:
image: scimgateway-data:latest
container_name: scimgateway-data
build:
context: .
dockerfile: DataDockerfile
# Docker version 1.13.0
#
# Depending on your system you may need to prefix the commands below with sudo.
#
# To build: docker build --force-rm=true -t <projectName>:1.0.0 .
# Example: docker build --force-rm=true -t scimgateway:1.0.0 .
#
# To tag as latest: docker tag <projectName>:1.0.0 <projectName>:latest
# Example: docker tag scimgateway:1.0.0 scimgateway:latest
#
# To run: docker run -d -e NODE_ENV=<environment> -e PORT=<port> -h localhost -p <external port>:<internal port> --name <projectName> <projectName>:latest
# Example: docker run -d -e NODE_ENV=development -e PORT=3000 -h localhost -p 8880:8880 --name scimgateway scimgateway:latest
# Debian Jessie linux with node user account and group
FROM node:6.9.2-slim
# Declare who maintains this Dockerfile
MAINTAINER Charles Watson <cwatsonx@costco.com>
# Add a Process ID 1 Safety Net. Specific to debian.
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init
# Setup environment or env variables with sane defaults. Note they can be overridden via the command line.
ENV NODE_ENV np # Either np or prod.
ENV PORT 8880
ENV SEED localhost
# Define your working directory for the node app.
WORKDIR /home/scimgateway
ENV NODE_HOME /home/scimgateway
# Add your project info
ADD ./package.json $NODE_HOME
# Install npm dependencies (exclude test stuff for dependencies)
RUN . ~/.bashrc && cd $NODE_HOME && npm install --production 2> npm_output.txt && npm cache clear 2> /dev/null
# Copy your project's code to your working directory
COPY . $NODE_HOME
# Default http port
EXPOSE 8880
# Start it up
CMD ["dumb-init", "node", "index.js"]
How to run scimgateway as a Docker image (using docker-compose). Note I tested this on a Debian Jessie several times. Additionally I tested with scimgateway 0.4.2 and 0.4.5 and both ran fine.
Docker Pre-requisites:
- docker-ce
- docker-compose
Install scimgateway following the instructions at https://github.com/jelhub/scimgateway.
mkdir myScimGateway
cd myScimGateway
npm init -y
npm install scimgateway --save
Add the following attached files in this Gist to your new scimgateway project:
-----------------------------
- docker-compose.yml <== Here is where you would set the exposed port and seed
- Dockerfile <== Main dockerfile
- DataDockerfile <== Handles volume mapping
Create a scimgateway user on your Linux VM. I'll let you choose the password
`adduser scimgateway`
Create a directory on your VM host for the scimgateway configs:
`mkdir /home/scimgateway/config`
Copy your updated scimgateway/config/plugin-loki.json file to /home/scimgateway/config. Use scp to perform the copy.
NOTE: /home/scimgateway/config is where all of important configuration and loki datastore will reside. **Outside of the running docker container. If you upgrade scimgateway you won't loose you configurations and data.**
Build docker images and start it up!
`docker-compose up --build -d`
NOTE: Add the -d flag to run the command above detached.
To confirm scimgateway created it loki.db:
```
su scimgateway
cd /home/scimgateway/config
ls loki.db
```
Be sure to confirm that port 8880 is available with a simple http request
To view the logs
`docker logs scimgateway`
To execute command within your running container:
`docker exec scimgateway <bash command>`
To stop scimgateway:
`docker-compose stop`
To restart scimgateway:
`docker-compose start`
To upgrade scimgateway docker image (remove the old stuff before running docker-compose up --build):
```
docker rm scimgateway
docker rm $(docker ps -a -q); docker rmi $(docker images -q -f "dangling=true")
```
Have fun!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment