Edit kubertes docker image pulled from docker hub

9/10/2017

I am super new to kubernetes and would like your help regarding following matter.

I have used docker pull php to pull httpd on my local.

How do I modify this image on my local?

-- noob
kubernetes

2 Answers

9/10/2017

You can't modify images used to build container in pod. You can however pull this image on a different node running docker, and use Dockerfile or docker commit to create a new image from the base image you wanted to modify or container running this image. After creating the new image, you tag it and upload to docker hub. Then you can pull your newly created image in docker hub to create a new container in pods

-- Innocent Anigbo
Source: StackOverflow

9/10/2017

Ok, I will start with the basics: as stated in the previous comments and answers, you cannot modify this image that is coming from the official PHP image on Docker Hub.

However, you have a couple of options when it comes to creating your own image:

  1. start from the PHH base image you just pulled and create your own image with a Dockerfile (where the app folder contains your application)

FROM php:7.1.9-apache COPY app /var/www/html EXPOSE 80

Then, you just docker build -t my-php-app . and in order to run it locally you docker run -p <some-port>:80 my-php-app.

This is the easiest way to create your new image and here you can find some good documentation.

  1. you can run the container, make some changes (add your files, edit configuration and other stuff) and then commit those changes into a new image. You can find some examples on docker commit here.

However, this second approach doesn't allow you to source control your image creation process (the way you do with a Dockerfile).

After you create your image, in order to deploy it on another node (other than the one you used to create it), you need to push the image to an image repository (Docker Hub, or some other private image registry - AWS, GCP and Azure all have private image registries). The default one using the Docker CLI is Docker Hub. Here you can find a tutorial on tagging and pushing your image to Docker Hub

Now that you have your image on Docker Hub (or another private image registry), you are ready to deploy it on your Kubernetes cluster.

You can run it in a very similar manner to the one you ran it using Docker:

kubectl run --image=<docker-hub-username>/<your-image> your-app-name --port=<port inside container>

Then, in order to access it from outside the cluster you need to expose the deployment which will create a service (and now depending on where your cluster is - cloud/on-prem you can get a public IP from the cloud provider or use the node port):

kubectl expose deployment your-app-name --port=80 --name=your-app-service

The next step would be to create YAML files for your deployments and services.

Hope this helps!

-- radu-matei
Source: StackOverflow