简体   繁体   中英

running modified Dockerfile on kubernetes with GCP

I have a Kubernetes v1.8.6 cluster on google cloud platform.

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.

I installed php docker image using the following kubernetes deployment yaml file:

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

it works.. so far so good.

now I want to extend this image to install CertBot on it.

so I created the following 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 .

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.

is there a way to directly install the Dockerfile that I created? 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. Then you need to push your image into a docker registry. Why? So that your pod can pull that image from that registry. Building image is not enough.

Now where should you keep that docker image. You can try 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.

In this case you want to push your image named tuxin-php . So you need to create a repository in docker hub ( https://hub.docker.com/ ) using same name tuxin-php . ( 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.

When you are pushing xxxx/tuxin-php , your image will be stored in tuxin-php repository under your username.

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.

Hope this will help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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