Search code examples
docker

docker create | Error response from daemon: No command specified


Attached there is my Dockerfile. My intention is to use the following command:

docker build -t fbprophet . && \
docker create --name=awslambda fbprophet && \
docker cp awslambda:/var/task/venv/lib/python3.7/site-packages/lambdatest.zip . \
docker rm awslambda

However, I always receive this error here:

Error response from daemon: No command specified

When running these commands here, it works. I have to run it in different shells so the container doesn't stop running before my export is done.

docker build -t fbprophet . && docker container rm awslambda && docker run -it --name=awslambda fbprophet bash
docker cp awslambda:/var/task/venv/lib/python3.7/site-packages/lambdatest.zip .

Dockerfile:

FROM lambci/lambda:build-python3.7

ENV VIRTUAL_ENV=/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

COPY requirements.txt .
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

WORKDIR /var/task/venv/lib/python3.7/site-packages

COPY lambda_function.py .
COPY .lambdaignore .

RUN echo "Package size: $(du -sh | cut -f1)"

RUN zip -9qr lambdatest.zip *
RUN cat .lambdaignore | xargs zip -9qr /var/task/lambdatest.zip * -x

Solution

  • Probably the easiest way to get files out of an image you've built is to mount a volume on to a container, and make the main container process just be a cp command:

    docker run \
      --rm \
      -v $PWD:/export \
      fbprophet \
      cp lambdatest.zip /export
    

    (If you've built an application that uses ENTRYPOINT ["python"] or some such, you need to specify --entrypoint /bin/cp before the image name, and then put the arguments after the image name. Using CMD instead avoids this complication.)

    Usually a Docker image has a packaged application (or a reasonable base one could build an application on), and running a container actually runs that application. An image is kind of an inconvenient way to just pass around files. You might find it easier and safer to run the same set of commands outside of Docker on your host to create a virtual environment, and you can just directly cp the file out of there when you're done.