docker run $PATH issue with minikube / kubernetes

5/21/2018

I have been trying to get one of my containers running locally with minikube [I am still quite new to all of this FYI]. Prior to building the container I have been running eval $(minikube docker-env) and I can see the 'new' container listed when I run docker images.

Here is my docker file for reference:

# start with python base
FROM python:3.6.4

# whom to come after if things break
LABEL maintainer="my_email_address"

# add tests to container
ADD . /app

ENV APP_PATH=/app

# set working directory
WORKDIR $APP_PATH

# install requirements for tests
RUN pip3 install --no-cache-dir -r requirements.txt

# clear all cached files
RUN find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf

# set env variables
ENV TEST $TEST \
USERNAME $USERNAME \
PASSWORD $PASSWORD \
USERNAME2 $USERNAME2 \
PASSWORD2 $PASSWORD2 \
AUTH_TOKEN_1 $AUTH_TOKEN_1 \
AUTH_TOKEN_2 $AUTH_TOKEN_2

# type of command
CMD pytest $TEST

# clean up
RUN rm -rf /tmp/* && rm -rf /var/lib/apt/lists/*

I then created this yml file for minikube, and at the end include a docker run command to pass in some env variables the container is expecting.

build.yml

apiVersion: v1
kind: Pod
metadata:
  name: api-test-pod-k
spec:
 containers:
 - name: api-test-container-k
   image: api-test-container-k
   imagePullPolicy: IfNotPresent
   command: ["docker run -e USER=root -e USERNAME='email@address.com' -e PASSWORD='xxxx' -e USERNAME2='email2@address.com' -e PASSWORD2='xxxx' -e AUTH_TOKEN_1='XXXXXX' -e AUTH_TOKEN_2='XXXXXX' -e TEST='test_* -m smoke' api-test-container-k"]

When I attempt to deploy the pod it end up in the status of

kubectl get pods
NAME                           READY     STATUS              RESTARTS   AGE
api-test-pod-k                 0/1       RunContainerError   0          14s

and the logs show the following:

kubectl logs -f api-test-pod-k
container_linux.go:265: starting container process caused "exec: \"docker run -e USER=root -e USERNAME='email@address.com' -e PASSWORD='xxxx' -e USERNAME2='email2@address.com' -e PASSWORD2='xxxx' -e AUTH_TOKEN_1='XXXXXX' -e AUTH_TOKEN_2='XXXXXX' -e TEST='test_* -m smoke' api-test-container-k\": executable file not found in $PATH"

What has me confused is that I can run this docker command locally without minikube in the mix there are no issues. Why would minikube / K8 treat this differently?

I know this is a lot of info. Thank you very much for your time.

-- Lombax
docker
kubernetes
minikube

1 Answer

5/21/2018

This line doesn't seem to be correct:

command: ["docker run -e USER=root ...

In that command section in your yaml, you can override the CMD line from your Dockerfile, but it's optional. Normally, you don't want to do that. In your case, you are trying to run the docker run inside your container and the error you are seeing is saying it can't find the docker command on your $PATH in the image.

Also it's a good practice to have the CMD pytest $TEST or ENTRYPOINT as the very last line in your dockerfile. For start, you can use some linter for dockerfiles, for instance this one.

-- Jiri Kremser
Source: StackOverflow