0
0
Dockerdevops~20 mins

Init container pattern in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Init Container Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Purpose of Init Containers in Kubernetes

What is the main purpose of using an init container in a Kubernetes Pod?

ATo provide a user interface for the application
BTo run setup tasks before the main application container starts
CTo scale the number of application containers automatically
DTo replace the main application container after it crashes
Attempts:
2 left
💡 Hint

Think about tasks that must finish before the main app runs.

💻 Command Output
intermediate
1:30remaining
Output of Init Container Status

Given the following kubectl get pod mypod -o json snippet showing init container status, what is the state of the init container?

{
  "status": {
    "initContainerStatuses": [
      {
        "name": "init-setup",
        "state": {
          "terminated": {
            "exitCode": 0,
            "reason": "Completed"
          }
        }
      }
    ]
  }
}
AInit container finished successfully
BInit container is still running
CInit container failed to start
DInit container was skipped
Attempts:
2 left
💡 Hint

Look at the exitCode and reason fields.

Configuration
advanced
2:30remaining
Correct Init Container YAML Configuration

Which YAML snippet correctly defines an init container that copies files from a shared volume before the main container starts?

A
initContainers:
  - name: init-copy
    image: busybox
    command: ['sh', '-c', 'cp /source/* /dest/']
    volumeMounts:
      - name: shared-data
        mountPath: /dest
containers:
  - name: app
    image: myapp
    volumeMounts:
      - name: shared-data
        mountPath: /app/data
volumes:
  - name: shared-data
    emptyDir: {}
B
initContainers:
  - name: init-copy
    image: busybox
    command: ['sh', '-c', 'cp /source/* /dest/']
containers:
  - name: app
    image: myapp
volumes:
  - name: shared-data
    emptyDir: {}
C
initContainers:
  - name: init-copy
    image: busybox
    command: ['cp', '/source/*', '/dest/']
    volumeMounts:
      - name: shared-data
        mountPath: /dest
containers:
  - name: app
    image: myapp
    volumeMounts:
      - name: shared-data
        mountPath: /app/data
volumes:
  - name: shared-data
    emptyDir: {}
D
containers:
  - name: init-copy
    image: busybox
    command: ['sh', '-c', 'cp /source/* /dest/']
    volumeMounts:
      - name: shared-data
        mountPath: /dest
initContainers:
  - name: app
    image: myapp
    volumeMounts:
      - name: shared-data
        mountPath: /app/data
volumes:
  - name: shared-data
    emptyDir: {}
Attempts:
2 left
💡 Hint

Check the placement of initContainers and volume mounts.

Troubleshoot
advanced
2:00remaining
Init Container Fails to Complete

You have an init container that never completes and blocks the main container from starting. Which of the following is the most likely cause?

AThe Kubernetes node is out of disk space
BThe main container image is missing
CThe pod has no resource limits set
DThe init container command is stuck waiting for input or a service that is not available
Attempts:
2 left
💡 Hint

Think about what can cause a container to hang during startup.

🔀 Workflow
expert
2:00remaining
Init Container Execution Order

Consider a Pod with three init containers named init1, init2, and init3. Which statement correctly describes their execution order?

AThey run randomly and independently of order
BThey run in parallel and the Pod starts when all finish
CThey run sequentially in the order defined in the Pod spec, each must complete before the next starts
DOnly the first init container runs; the others run only if the first fails
Attempts:
2 left
💡 Hint

Think about how Kubernetes ensures setup tasks complete before the app runs.