简体   繁体   English

使用GCP在kubernetes上运行修改后的Dockerfile

[英]running modified Dockerfile on kubernetes with GCP

I have a Kubernetes v1.8.6 cluster on google cloud platform. 我在Google云端平台上有一个Kubernetes v1.8.6集群。

my desktop is a macbook pro with high sierra, kubectl installed using the google-cloud-sdk an docker is installed as a vm using homebrew. 我的桌面是Macbook Pro,具有高山脉,使用google-cloud-sdk安装了kubectl,使用自制软件将docker安装为vm。

I installed php docker image using the following kubernetes deployment yaml file: 我使用以下kubernetes部署yaml文件安装了php docker镜像:

apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
  name: php-deployment
  labels:
    app: php
spec:
  replicas: 1
  selector:
    matchLabels:
      app: php
  template:
    metadata:
      labels:
        app: php
    spec:
      containers:
      - name: php
        image: php:7.1.13-apache-jessie
        volumeMounts:
        - mountPath: /var/www/html
          name: httpd-storage
        - mountPath: /etc/apache2
          name: httpd-conf-storage
        - mountPath: /usr/local/etc/php
          name: php-storage
        ports:
        - containerPort: 443
        - containerPort: 80
      volumes:
      - name: httpd-storage
        gcePersistentDisk:
            fsType: ext4
            pdName: httpd-disk
      - name: httpd-conf-storage
        gcePersistentDisk:
            fsType: ext4
            pdName: httpd-conf-disk
      - name: php-storage
        gcePersistentDisk:
            fsType: ext4
            pdName: php-disk

I installed it with kubectl create -f yaml.file 我用kubectl create -f yaml.file安装了它

it works.. so far so good. 它有效..到目前为止很好。

now I want to extend this image to install CertBot on it. 现在,我想扩展此映像以在其上安装CertBot。

so I created the following Dockerfile : 所以我创建了以下Dockerfile

FROM php:7.1.13-apache-jessie

RUN bash -c 'echo deb http://ftp.debian.org/debian jessie-backports main >> /etc/apt/sources.list'
RUN apt-get update
RUN apt-get install -y python-certbot-apache -t jessie-backports

I placed this file in directory called build and built an image out of the dockerfile using docker build -t tuxin-php ./build . 我将此文件放置在名为build目录中,并使用docker build -t tuxin-php ./build从dockerfile中docker build -t tuxin-php ./build

I have no idea where the docker image is placed because docker is running out of a VM in high sierra and I'm a bit confused if I have local access or need to do scp, but it may not needed. 我不知道将docker映像放在何处,因为docker在高塞拉利昂(Super Sierra)的虚拟机用完了,如果我具有本地访问权限或需要执行scp,我有点困惑,但是可能不需要。

is there a way to directly install the Dockerfile that I created? 有没有一种方法可以直接安装我创建的Dockerfile? do I have to create the image and somehow to install it? 我必须创建映像并以某种方式安装它吗? and if so how ? 如果可以的话?

I'm a bit confused so any information regarding the issue would be greatly appreciated. 我有些困惑,因此不胜感激。

thank you 谢谢

First of all, you need to build your docker image. 首先,您需要构建您的docker映像。 Then you need to push your image into a docker registry. 然后,您需要将映像推送到Docker注册表中。 Why? 为什么? So that your pod can pull that image from that registry. 这样您的Pod可以从该注册表中提取该映像。 Building image is not enough. 建筑图像还不够。

Now where should you keep that docker image. 现在您应该在哪里保存该Docker映像。 You can try https://hub.docker.com/ . 您可以尝试https://hub.docker.com/

You can follow these steps: 您可以按照以下步骤操作:

Use these command 使用这些命令

$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: <your docker hub username>
Password: <your docker hub password>

Now you are ready to push your docker image into your registry. 现在,您可以将Docker映像推送到注册表中了。

In this case you want to push your image named tuxin-php . 在这种情况下,您要推送名为tuxin-php映像。 So you need to create a repository in docker hub ( https://hub.docker.com/ ) using same name tuxin-php . 因此,您需要使用同名tuxin-php hub( https://hub.docker.com/ )中创建一个存储库。 ( https://docs.docker.com/docker-hub/repos/ ) https://docs.docker.com/docker-hub/repos/

Try this now 立即尝试

$ docker build -t xxxx/tuxin-php ./build
$ docker push xxxx/tuxin-php

Here, xxxx is your docker username. 在这里, xxxx是您的docker用户名。

When you are pushing xxxx/tuxin-php , your image will be stored in tuxin-php repository under your username. 当您按xxxx/tuxin-php ,您的映像将以您的用户名存储在tuxin-php存储库中。

And finally, you have to use this image. 最后,您必须使用此图像。

containers:
- name: php
  image: xxxx/tuxin-php

Your pod will pull xxxx/tuxin-php from docker hub. 您的pod将从xxxx/tuxin-php hub提取xxxx/tuxin-php

Hope this will help 希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM