Skip to content

Instantly share code, notes, and snippets.

@todd-dsm
Last active September 6, 2023 21:43
Show Gist options
  • Save todd-dsm/5cc9afaa08be59c64153cc0c02992399 to your computer and use it in GitHub Desktop.
Save todd-dsm/5cc9afaa08be59c64153cc0c02992399 to your computer and use it in GitHub Desktop.
run a container that accepts commands and arguments
# This is an initContainer:
# REF: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
# It is configured in a pod like any other container, except that it is
# specified inside its own "initContainers" section.
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: busybox:1.28
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
resources:
requests:
cpu: "250m"
memory: "64Mi"
limits:
cpu: "500m"
memory: "128Mi"
initContainers:
- name: init-myservice
image: busybox
command: ['sh', '-c', 'git clone <some-repository-that-will-be-used-by-application> ;']
# * Use initContainers when attempting to run any command or task that will only
# be run one time after the pod is created. The initContainer will complete
# its task before the main container is started.
# * If any of the initContainers fail to complete, Kubernetes restarts the Pod
# repeatedly until the Init Container succeeds.
@todd-dsm
Copy link
Author

todd-dsm commented Sep 6, 2023

Dockerfiles are fairly straightforward. This is an overly simplified container that:

  1. initializes
  2. echos 'yo!'
  3. and exits
FROM alpine:latest
WORKDIR /tmp
ENTRYPOINT ["echo"]
CMD [ "yo!" ]

I would only spend time on building a container and focus on the ENTRYPOINT directive.

Building a container that accepts commands and args from Kubernetes yaml (example: L15 above) then that's a majority of the Docker's value. For everything else, there's buildpacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment