Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the workdir of a container launched by Kubernetes

Is it possible to set the working directory when launching a container with Kubernetes ?

like image 430
pditommaso Avatar asked Apr 14 '16 21:04

pditommaso


People also ask

How does Kubernetes set environment variables?

Environment Variables and Kubernetes There are two ways to define environment variables with Kubernetes: by setting them directly in a configuration file, from an external configuration file, using variables, or a secrets file.

How do I change my Kubernetes restart policy?

Once you created the pod, kubernetes makes some properties immutable. These are mostly the options which can change pods stability, for example this. You can get the manifest using kubectl get pod $PODNAME -o yaml --export . Then edit this manifest and change the restartPolicy field to Never and redeploy it.

What is the Docker Workdir?

The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile. Any RUN , CMD , ADD , COPY , or ENTRYPOINT command will be executed in the specified working directory.


2 Answers

Yes, through the workingDir field of the container spec. Here's an example replication controller with an nginx container that has workingDir set to /workdir:

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: nginx
    spec:
      containers:
        - name: nginx
          image: mynginximage
          workingDir: /workdir
like image 77
ghodss Avatar answered Oct 16 '22 16:10

ghodss


It should be also possible to set the working directory using env and command attributes. Below is an example:

apiVersion: v1 kind: Pod metadata:   name: print-greeting spec:   containers:   - name: env-print-demo     image: bash     env:     - name: GREETING       value: "Warm greetings to"     - name: HONORIFIC       value: "The Most Honorable"     - name: NAME       value: "Kubernetes"     command: ["echo"]     args: ["$(GREETING) $(HONORIFIC) $(NAME)"]
like image 41
Deb Avatar answered Oct 10 '22 19:10

Deb