skip to Main Content

I’m trying to export a container, import it and then run it. But, the CMD/ENTRYPOINT in dockerfile is not executing on the imported container.

How do I execute the same commands specified in Dockerfile when the image was built? I know that it can be specified with docker run image <cmd> but, how is the CMD/ENTRYPOINT lost in the export/import process? And, is there a better way for importing/exporting containers?

Here is the dockerfile:

FROM python:3-alpine

WORKDIR app

ADD ./app.py .
ADD ./requirements.txt .
RUN pip3 install -r requirements.txt

CMD ["python3", "app.py"]

And the commands run in succession:

docker build . -t python-app
docker run --name app-container python-app    
docker export app-container > app-container.tar  
docker import app-container.tar "import-container:latest"  
docker run --name import import-container:latest    
# docker: Error response from daemon: No command specified.

2

Answers


  1. docker export exports the filesystem of a container, not an image. That’s why the CMD and ENTRYPOINT aren’t exported.

    If you want to make a tar file from an image, you should use docker save and docker load rather than docker export and docker import.

    Login or Signup to reply.
  2. When you do docker import you need to do:

    docker import --change 'CMD ["python3", "app.py"]' image_archive.tar)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search