Is there any better way for changing the source code of a container instead of creating a new image?

5/23/2018

What is the best way to change the source code of my application running as Kubernetes pod without creating a new version of image so I can avoid time taken for pushing and pulling image from repository?

-- Arun
docker
kubernetes

6 Answers

4/10/2019

This is definitely not recommended for production.

But if your intention is local development with kubernetes, take a look at these tools:

Telepresence

Telepresence is an open source tool that lets you run a single service locally, while connecting that service to a remote Kubernetes cluster.

Kubectl warp

Warp is a kubectl plugin that allows you to execute your local code directly in Kubernetes without slow image build process.

The kubectl warp command runs your command inside a container, the same way as kubectl run does, but before executing the command, it synchronizes all your files into the container.

-- Eduardo Baitello
Source: StackOverflow

4/10/2019

I think it should be taken as process to create new images for each deployment. Few benefits:

  • immutable images: no intervention in running instance this will ensure image run in any environment
  • rollback: if you encounter issues in new version, rollback to previous version
  • dependencies: new versions may have new dependencies
-- Akash Sharma
Source: StackOverflow

5/23/2018

You may enter the container using bash if it installed on the image and modify it using -

docker exec -it <CONTAINERID> /bin/bash 

However, this isn’t advisable solution. If your modifications succeed, you should update the Dockerfile accordingly or else you risk losing your work and ability to share it with others.

-- scourer
Source: StackOverflow

5/23/2018

Another way to achieve a similar result is to leave the application source outside of the container and mount the application source folder in the container.

This is especially useful when developing web applications in environments such as PHP: your container is setup with your Apache/PHP stack and /var/www/html is configured to mount your local filesystem.

If you are using minikube, it already mounts a host folder within the minikube VM. You can find the exact paths mounted, depending on your setup, here:

https://kubernetes.io/docs/getting-started-guides/minikube/#mounted-host-folders

Putting it all together, this is what a nginx deployment would look like on kubernetes, mounting a local folder containing the web site being displayed:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
 replicas: 1
  template: 
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: /var/www/html/
          name: sources
          readOnly: true
      volumes:
      - name: sources
        hostPath:
          path: /Users/<username>/<source_folder>
          type: Directory
-- eschnou
Source: StackOverflow

7/22/2018

Finally we have resolved the issue. Here, we changed our image repository from docker hub to aws ecr in the same region where we are running kubernetes cluster. Now, it is taking very lesstime for pushing/pulling images.

-- Arun
Source: StackOverflow

5/23/2018

Have the container pull from git on creation?

Setup CI/CD?

-- Nathan Ogden
Source: StackOverflow