1. Install docker and Kubernetes CLI
choco install docker-desktop choco install kubernetes-cli
Now you can check the installation by checking their versions.
docker -v kubectl version
The kubectl command may return the following error for the 2nd connection:
Unable to connect to the server: dial tcp [::1]:6445: connectex: No connection could be made because the target machine actively refused it.
This means you don’t have Kubernetes yet.
2. Installing Kubernetes cluster
Install Kubernetes as it suggested by Docker in the client app.
In order to configure Kubernetes you need to configure network switch in Hyper-V and network adapter (sharing option). Read here.
The alternative way of installing a Kubernetes cluster is the using of of Minikube.
It also requires configuration of Hyper-V switch. On Windows system it’s less preferable because its own image registry and it’s very complicated to deploy an image created with Docker on Minikube cluster.
Deleting Minikube and cluster
If you installed with
choco run the following commands:
minikube stop minikube delete choco uninstall minikube choco uninstall kubernetes-cli
After that delete the following folders:
3. Deploying to Docker
Create a docker image from the folder with your appplication:
docker build -t mydockerimage .
. (dot) in the end refers to the current catalog. The very simple deployment is just running a command:
docker run -p 3001:3000 mydockerimage
-p maps internal port which the application listens to an external one. Using the command above you’ll be able to see your deployed application using
4. Using of Docker-Compose
The easiest way of deploying several application to docker is using
docker-compose. The command below performs the same deployment as we you did before with
version: '3' services: server: image: "mydockerimage" build: context: . dockerfile: ./dockerfiles/Dockerfile.server ports: - "3001:3000"
In contrast the deployment with
docker-compose may be done with just only one command:
docker-compose up -d
-d stands for
detached. This means the app will run in background.
In order to stop your deployment just run the following:
docker-compose you can deploy several apps and define number of replicas for each of them. Ream more here.
5. Cleaning Resources
After creating a new image you may want to remove previous and not used resources. In order to remove docker images use the following commands:
# to clear all $ docker system prune # to clear images $ docker image prune -a --filter "until=12h"
docker-compose use the following command when composing a new version (with option
docker-compose up -d --remove-orphans