This is a demo application from the Docker for Web Developers course on Pluralsight that demonstrates how multiple services can be integrated and orchestrated using Docker and Docker Compose.
Open a WSL (Linux) command prompt and clone the repo from there into a folder of your choosing. For example you can cd
into desktop
and put it there if you'd like.
git clone https://github.com/danwahlin/codewithdandockerservices.git
Ensure that Node is installed into your Linux instance (see https://docs.microsoft.com/windows/nodejs/setup-on-wsl2?WT.mc_id=m365-0000-dwahlin).
Note that if you're NOT using WSL at all with Docker on Windows then you can clone the repo from any Windows command prompt.
-
Install Docker Desktop for Mac or Docker Desktop for Windows from https://docker.com and the lastest LTS version of Node.js from https://nodejs.org.
-
Set the environment variables in your command window.
export APP_ENV=development
export DOCKER_ACCT=codewithdan
NOTE: For the Windows DOS command shell use
set
instead ofexport
. For Windows Powershell use$env:KEY = "value"
:$env:APP_ENV="development"
$env:DOCKER_ACCT="codewithdan"
-
Run
npm install
to install the Node.js dependencies for the project (when running containers in development mode since a volume is defined docker-compose.yml file) -
Run
docker-compose build
-
Run
docker-compose up
-
Wait until everything has finished loading in the console (may take 60 seconds or so) and then visit https://localhost in a browser. You may need to refresh a few times to see the data displayed (typically a timing issue if you try it too soon).
-
Live long and prosper
-
Enable Kubernetes in Docker Desktop.
Note:
You MUST have Docker Desktop
for this particular demo to work or another local Kubernetes option such as Minikube. -
Do a
production
Docker Compose build (seedocker-compose.yml
for instructions on doing the build) to create the local images. Ensure that you set APP_ENV=production as mentioned in the compose file. -
Open a command-prompt at the root of the project
-
Run the following to add the database passwords as secrets (yes - these are simple passwords for the demo :-)):
kubectl create secret generic db-passwords --from-literal=db-password='password' --from-literal=db-root-password='password'
Note:
password
is being used here purely to keep things very simple for the demo. Use strong passwords for a "real" setup!!!! -
Run
kubectl create -f .k8s
to create the Kubernetes Services, Deployments, Pods, etc. -
Once the deployments are applied several pods will be created.
-
Open the browser and go to https://localhost. Read note below.
NOTE: You'll need to wait since it'll take a little bit for the DB to start up. Once the Pods are ready you should see data in the app (hit refresh if needed).
- When you're done run
kubectl delete -f .k8s
to delete the Kubernetes resources.
NOTE: The local storage hostname volume is commented out in the .k8s/mongo.deployment.yml
StatefulSet because MongoDB doesn't support that type of volume
correctly on Docker for Windows. It does work on Mac/Linux. You'd need to create a /tmp/data/db
directory and then uncomment the
volumes
and volumeMounts
properties (and sub-properties) in the StatefulSet to actually use the volume on Mac/Linux.
This demo includes a LoadBalancer service for the nginx Pod which is why you can hit https://localhost.
To expose a specific port for localhost for the nginx Pod, get the name of the nginx
pod by running
kubectl get pods
and use the pod name in the following command:
sudo kubectl port-forward [name-of-nginx-pod] 8080:80
Note that sudo is needed to enable port 80 in this case on Mac. You can choose a different port as well such as 8081:80.
-
Open a command-prompt at the root of the project
-
Run the following to add the database passwords as secrets (yes - these are simple passwords for the demo :-)):
kubectl create secret generic db-passwords --from-literal=db-password='password' --from-literal=db-root-password='password'
Note:
password
is being used here purely to keep things very simple for the demo. Use strong passwords for a "real" setup!!!! -
Install Skaffold from https://skaffold.dev.
-
Run the following command at the root of the project:
skaffold dev