Deploy docker image on osx to Kubernetes

7/9/2018

I want to deploy a simply docker container to my Kubernetes cluster. I'm on Docker for Mac (Edge mode since that's what supports Kubernetes), and I don't know how to push my image to my Google Cloud Container Registry.

Following the docs, I run:

docker stack deploy --compose-file ./docker-compose.yml my-app

and I get this in return:

Ignoring unsupported options: build

this node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again

And here is my docker-compose.yml:

version: '3'
services:
  web:
    build: ./
    environment:
      FLASK_APP: myApp
      FLASK_ENV: development
    command: flask run --host=0.0.0.0
    ports:
      - "9090:5000"
    volumes:
      - ./app:/app
volumes:
  data:
    driver: local

What am I doing wrong?

-- AlxVallejo
docker
docker-compose
kubernetes

1 Answer

7/10/2018

To push a Docker image to a remote Docker registry you need to follow the next steps:

  1. Build your Docker image, e.g., docker build .
  2. Tag your image with name of remote registry docker tag <image_name> <repository_name_or_address>/<image_name>
  3. Login to the remote registry using docker login <repository_name_or_address> command
  4. Push your image using docker push <repository_name_or_address>/<image_name> command

Steps for authorization can differ for various types of repositories. For Google Cloud Container Registry, you need to look through this link. For more information, you can also visit the link on the Docker official site.

After you push the image to the remote Docker registry, you can use it in Kubernetes. The simplest command for that is kubectl run <name_of_your_deployment> --image=<repository_name_or_address>/<image_name>

It is possible that you will need to configure Kubernetes for pulling images from your private repository. In this case, use instructions posted here.

-- Artem Golenyaev
Source: StackOverflow