Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

How can I make a Docker container that can run a bash command and has mysql installed for testing a Helm chart?

I have a Helm chart that deploys a docker container containing MySQL. I want to also do a Helm test (which is really just another deployment of a container that you can tell it to run commands on). The two things I need installed are:

  • Bash
  • MySql client

I tried using the bats/bats Docker container but it throws the error:

Error: failed to start container "db-test": Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: "/bin/bash": stat /bin/bash: no such file or directory": unknown

How would I make a Dockerfile that would have installed the software I need to run this test?

My Current Test YAML

{{- if .Values.db.enabled }}
apiVersion: v1
kind: Pod
metadata:
  name: "{{ .Release.Name }}-credentials-test"
  namespace: {{ quote .Values.metadata.namespace }}
  annotations:
    "helm.sh/hook": test
spec:
  containers:
    - name: {{ .Release.Name }}-credentials-test
      image: "bats/bats:1.2.1"
      imagePullPolicy: "IfNotPresent"
      env:
        - name: MYSQL_HOST
          value: {{ include "db-application.name" . }}
        - name: MYSQL_PORT
          value: "3306"
        - name: MYSQL_USER
          valueFrom:
            secretKeyRef:
              name: db-credentials
              key: db-username
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: db-credentials
              key: db-password
      command:
        - /bin/bash
        - -ec
        - |
          mysql --host=$MYSQL_HOST --port=$MYSQL_PORT --user=$MYSQL_USER --password=$MYSQL_PASSWORD
  restartPolicy: Never
{{- end }}

Essentially, I need a container from which I can run this command:

/bin/bash -ec mysql --host=$MYSQL_HOST --port=$MYSQL_PORT --user=$MYSQL_USER --password=$MYSQL_PASSWORD
question from:https://stackoverflow.com/questions/65947207/how-can-i-make-a-docker-container-that-can-run-a-bash-command-and-has-mysql-inst

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...