Configuration Flashcards
How do you create your own image?
Create a dockerfile and put all the steps in it, that would be necessary normally, in order.
i.e:
FROM Ubunto
RUN apt-get update
RUN apt-get install python
RUN pip install flask
RUN pip install flask-mysql
COPY . /opt/source-code
ENTRYPOINT FLASK_APP=/opt/source-code/app.py flask run
—X
Then build the Dockerfile
‘docker build Dockerfile -t maratajc/my-custom-app
-> creates the file locally
Then
‘docker push maratajc/my-custom-app’ pushs it to the docker repo
my-custom-app = image name
How are Dockerfiles structured?
INSTRUCTION ARGUMENT
-> what to do when creating the image
Every dockerfile needs to start from an OS, or an image that was created before, based on an OS (FROM Ubuntu)
RUN instructs to run a certain command on the images
COPY copies files from local system onto the image
ENTRYPOINT allows a command, when an image is run as a container
How can you specify commands to be run in a pod at start?
spec: containers: - name: image: command: ["sleep","5000"]
or
~~~
command:
- sleep
- “5000”
~~~
How do you add commands/arguments to the command that is run when a container is started?
In the Dockerfile
After ENTRYPOINT
add CMD [”–color”, “red”] for final command to have ‘… –color red’
What happens when a command in the pod-yaml is different to the Dockerfile?
- only the command from the yaml is run
In a Dockerfile how do ENTRYPOINT and CMD work together?
Whatever is written inside CMD gets appended to the ENTRYPOINT command
What happens if in a Dockerfile a CMD instruction is given and in the cl a different instruction is given?
I.e.
ENTRYPOINT [“sleep”]
CMD [“5”]
vs.
docker run ubuntu-sleeper 10
The cl instruction overwrites the Dockerfile CMD
How can you overwrite an ENTRYPOINT of a Dockerfile?
using ‘–entrypoint’ option
docker run –entrypoint sleep2.0 ubuntu sleeper 10
How can you specify arguments to be given to the underlying CRI?
apiVersion: kind: metadata: spec: - name: ubuntu-sleeper image: ubuntu-sleeper args: ["10"]
What information can be changed on an existing pod?
spec.containers[x].image
spec.initContainers[x].image
spec.activeDeadlineSeconds
spec.tolerations
What is different for changing an existing pod and changing an existing deployment?
For pods only specific fields can be changed.
For deployments any field can easily be changed. As a consequence the running pods are replaced
How do you set an environemnt variable?
In pod/template
spec: containers: - name: image: env: - name: App-COLOR VALUE: pink
What are ways of setting environment variables?
- manually, as key-value directly in spec
- through a ConfigMap
- through Secrets
How do you set environment variables trough Config maps
spec: - ... valueFrom configMapKeyRef:
How do you set environment variables trough Secrets?
spec: ... - env: - name: APP_Color secretKeyRef