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

3/20/2018

I am trying to follow the instructions at https://docs.docker.com/docker-for-windows/kubernetes/#use-docker-commands for running a docker-compose.yml file against kubernetes on Docker for Windows.

I am using the Edge version of Docker for Windows -- 18.03.0-ce-rc4 -- and I have kubernetes enabled.

I am using the example docker-compose app at https://docs.docker.com/compose/gettingstarted/#step-3-define-services-in-a-compose-file, i.e.

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

This example works fine with docker-compose build and docker-compose up

But following the documentation linked above for docker stack, I get the following:

PS C:\dev\projects\python\kubetest> docker stack deploy --compose-file .\docker-compose.yml mystack
Ignoring unsupported options: build

Stack mystack was created
Waiting for the stack to be stable and running...
 - Service redis has one container running
PS C:\dev\projects\python\kubetest> kubectl get services
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)     AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP     5d
redis        ClusterIP   None         <none>        55555/TCP   8s

Note that it doesn't create the web service, along with that "ignoring unsupported options: build" error

I also tried using the sample docker-compose.yml file in that documentation linked above, and it didn't work, either, with a totally different error.

In short, by following the documentation, I'm unable to get anything deployed to kubernetes on Docker for Windows.

-- marc esher
docker
docker-compose
docker-for-windows
kubernetes

3 Answers

1/21/2019

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

-- yeze322
Source: StackOverflow

3/21/2018

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 .
-- Matt
Source: StackOverflow

3/11/2019

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.

-- Investigator
Source: StackOverflow