Deploying a docker-compose app on Kubernetes on Docker for Windows Deploying a docker-compose app on Kubernetes on Docker for Windows kubernetes kubernetes

Deploying a docker-compose app on Kubernetes on Docker for Windows


Due to the lack of support for a build there would be no image to run for the web service containers.

Compose can manage the build for you on a single Docker host. As Swarm and Kubernetes are normally run across multiple nodes, an image should reference a registry available on the network so all nodes can access the same image.

Dockers stack deploy example includes a step to setup a private registry and use that for source of the image:

services:  web:    image: 127.0.0.1:5000/stackdemo

Workaround

In this instance, it might be possible to get away with building the image manually and referencing that image name due to everything running under the one Docker instance, it depends on how Kubernetes is setup.

version: '3.3'services:  web:    build: .    image: me/web    ports:      - '5000:5000'  redis:    image: redis

Build the image externally

docker-compose build web

or directly with docker:

docker build -t me/web .


there is a project:

https://github.com/kubernetes/kompose

called Docker Kompose that helps users who already have docker-compose files to deploy their applications on Kubernetes as easy as possible by automatically converting their existing docker-compose file into many yaml files.


I ran into the same problem when following the official instruction.

To bypass this issue, I chose using kubectl for deploying docker images to local k8s instead of using docker stack (seems the root cause might be the --orchestrator kubernetes flag, it doesn't work).

Here are the steps:

  1. Using the Kubernetes' docker registry per terminal (important):

    run & minikube docker-env | iex under Windows Powershell (iex is the alias of Invoke-Expression)

    or

    run eval $(minikube docker-env) under bash environment.

    After that, run docker image ls, make sure your docker registry is set to Kubernetes's env. (You should see some default images under 'k8s.gcr.io' domain.)

    You may need to do this in every terminal if multiple terminals are opened.

  2. Rebuild your docker image:

    run docker-compose -f /path/to/your/docker-compose.yml build

    Your image should appear in K8s's local registry.

  3. Run your image with 'kubectl':

    run kubectl run hello-world --image=myimage --image-pull-policy=Never

References:

https://stackoverflow.com/a/48999680/4989702