How to create a file, insert string to file and set it's permissions in kubernetes pod

255 Views Asked by At

For some reason, I am unable to do this in the docker file when creating the docker image. I think it's because of the VOLUME statement. Some suggested to run the VOLUME statement before the creation of the file and setting the permissions but it doesn't matter what order it's done in, it just doesn't work.

So I am left with trying to use the model file to create the file, insert the data and set the permissions. I've tried to many combinations but none of it works. I don't know this stuff very well so would appreciate any ideas.

What commands can I use in the below code to create a file, add a key to it and then set permissions like chmod 600?

Here's the code:

containers:
    mongo:
      image: mongo
      imageVersion: 3.0.4

      lifecycle:
        command:
          - mongod
        args:
          - --config
          - /etc/mongo/mongod.conf
      services:
        - port: 27017
          nodePort: ${{ vars.nodePorts["mongo_" + subnames[1] + "_" + location] }}

      volumeMappingSet:
        - PERSISTED:/data/db

      resources:
        cpu: tiny
        memory: tiny

Here's the docker file code:

RUN mkdir -p /ls -lrt data/db /data/configdb && \
    chown -R mongodb:mongodb /data/db /data/configdb

USER mongodb:mongodb

RUN  touch /data/db/replica.key && \
  echo -e 'key'\
      >> /data/db/replica.key && \
      chown mongodb:mongodb /data/db/replica.key && \
      chgrp mongodb /data/db/replica.key && \
      chmod 600 /data/db/replica.key

VOLUME /data/db /data/configdb
EXPOSE 27017

CMD ["mongod"]
0

There are 0 best solutions below