Complete the Docker Compose service to add an init container using the correct key.
services:
app:
image: myapp:latest
[1]:
- init-myservice
init-myservice:
image: busybox
command: ['sh', '-c', 'echo Init container running']The correct key to define dependencies between services in Docker Compose is depends_on. Docker Compose does not support init containers natively, so initContainers is not valid here. The depends_on key ensures that the init-myservice service starts before the app service.
Complete the Kubernetes pod spec to add an init container that runs a shell command.
apiVersion: v1 kind: Pod metadata: name: mypod spec: [1]: - name: init-myservice image: busybox command: ['sh', '-c', 'echo Init container running'] containers: - name: app image: myapp:latest
The initContainers field is used in Kubernetes pod specs to define init containers that run before app containers.
Fix the error in the init container command to correctly run a shell script.
initContainers: - name: init-myservice image: busybox command: ['[1]', '-c', 'echo Init container running']
The sh shell is available in the busybox image and is used to run shell commands. Using bash would fail if bash is not installed.
Fill both blanks to define an init container that creates a directory before the main container starts.
initContainers: - name: init-dir image: busybox command: ['[1]', '-c', 'mkdir -p /data'] containers: - name: app image: myapp:latest volumeMounts: - name: data-volume mountPath: [2]
The init container uses sh to run the mkdir command. The main container mounts the volume at /data to use the directory created.
Fill all three blanks to create a pod spec with an init container that waits for a file before starting the app container.
apiVersion: v1 kind: Pod metadata: name: wait-pod spec: initContainers: - name: wait-for-file image: busybox command: ['[1]', '-c', 'until test -f /data/ready.txt; do echo waiting; sleep 2; done'] volumeMounts: - name: data-volume mountPath: [2] containers: - name: app image: myapp:latest volumeMounts: - name: data-volume mountPath: [3] volumes: - name: data-volume emptyDir: {}
The init container uses sh to run the wait loop. The volume is mounted at /data in the init container and /app/data in the app container, showing how mount paths can differ.