Search code examples
dockerkubernetesdocker-composedocker-for-windows

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


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.


Solution

  • 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 .