【问题标题】:Cannot bind ports to my container in Google Container optimized VM无法在 Google Container 优化 VM 中将端口绑定到我的容器
【发布时间】:2015-05-29 08:25:42
【问题描述】:

我正在尝试在 GCE 中的 Google Container-optimized VM 上运行 docker 容器。

这是我的 dockerfile。我构建了一个容器镜像并将其推送到 gcr.io。

FROM nginx:1.9
COPY config /etc/nginx

我还写了一个容器清单文件。

version: v1beta2
containers:
  - name: test
    image: gcr.io/myproject/test
    ports:
      - name: http
        hostPort: 80
        containerPort: 80
      - name: https
        hostPort: 443
        containerPort: 443

我使用清单文件部署到 GCE,但端口绑定与我预期的不同。为什么主机端口 80 和 443 重定向到 google_containers/pause 而不是 myproject/test?

local$ gcloud compute instance create test \
  --image container-vm \
  --metadata-from-file google-container-manifest=container.yaml \
  --zone us-central1-b \
  --machine-type f1-micro \
  --tags http-server,https-server

local$ gcloud compute ssh --zone us-central1-b test

test$ sudo docker ps -a
CONTAINER ID IMAGE                                COMMAND              CREATED        STATUS        PORTS                                    NAMES
818828ccc2c6 gcr.io/myproject/test:latest         "nginx -g 'daemon of 23 seconds ago Up 22 seconds                                          k8s_test.9de3822_7f9f8ecace94a22b2bea59ee14f3bcd0-test_df40d10c4dfa4
f40d10c4dfa4 gcr.io/google_containers/pause:0.8.0 "/pause"             32 seconds ago Up 31 seconds 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp k8s_POD.c6ce2a78_7f9f8ecace94a22b2bea59ee14f3bcd0-test_default_7f9f8ecace94a22b2bea59ee14f3bcd0-test_64d51838

【问题讨论】:

    标签: docker google-compute-engine


    【解决方案1】:

    我已将清单 v1beta2 的版本更新为 v1 (v1beta3) 并再次尝试。端口绑定的结果好像和上一个一样,但是容器可以通过80和443端口与外网通信。

    version:1
    kind: Pod
    spec:
        restartPolicy: Always
        dnsPolicy: Default
        containers:
            - name: test
              image: gcr.io/myproject/test
              imagePullPolicy: Always
              ports:
                  - name: http
                    hostPort: 80
                    containerPort: 80
                    protocol: TCP
                  - name: https
                    hostPort: 443
                    containerPort: 443
                    protocol: TCP
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-27
      • 2018-12-09
      • 2014-12-20
      • 1970-01-01
      • 2022-01-02
      • 2015-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多