How do I run private docker images on Google Container Engine

£可爱£侵袭症+ 提交于 2019-11-28 15:49:02

问题


How do I run a docker image that I built locally on Google Container Engine?


回答1:


You can push your image to Google Container Registry and reference them from your pod manifest.

Detailed instructions

Assuming you have a DOCKER_HOST properly setup , a GKE cluster running the last version of Kubernetes and Google Cloud SDK installed.

  1. Setup some environment variables

    gcloud components update kubectl
    gcloud config set project <your-project>
    gcloud config set compute/zone <your-cluster-zone>
    gcloud config set container/cluster <your-cluster-name>
    gcloud container clusters get-credentials <your-cluster-name>
    
  2. Tag your image

    docker tag <your-image> gcr.io/<your-project>/<your-image>
    
  3. Push your image

    gcloud docker push gcr.io/<your-project>/<your-image>
    
  4. Create a pod manifest for your container: my-pod.yaml

    id: my-pod
    kind: Pod
    apiVersion: v1
    desiredState:
      manifest:
        containers:
        - name: <container-name>
          image: gcr.io/<your-project>/<your-image>
        ...
    
  5. Schedule this pod

    kubectl create -f my-pod.yaml
    
  6. Repeat from step (4) for each pod you want to run. You can have multiple definitions in a single file using a line with --- as delimiter.




回答2:


The setup I use is to deploy my own docker registry combined with ssh port forwarding. For that purpose I set up a ssh server in the cluster and use ~/.ssh/config to configure a port forward to the registry.

Also I use jenkins to build the images right in the cloud.




回答3:


Step 1: Specify the container in which you have to work on

gcloud container clusters get-credentials [$cluster_name]

Step 2: Tag the docker image you want to run

docker tag nginx gcr.io/first-project/nginx

Step 3: Push image

gcloud docker push gcr.io/first-project/nginx

Step4:Create yaml file (test.yaml)

apiVersion: v1
kind: Pod
containers:
- name : nginx1
  image: gcr.io/first-project/nginx

Step 5 : Create the pod

kubectl create –f test.yaml



回答4:


You could copy the registry authentication key of your private docker registry to the .dockercfg file in the root directory of the minions right before starting the pods. Or run docker login on minions before starting.

    docker login --username=<> --password=<> --email=<> <DockerServer>

Referring to the private docker image in the pod configuration should then work as expected.



来源:https://stackoverflow.com/questions/26788485/how-do-i-run-private-docker-images-on-google-container-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!