2

I'm writing below script which will build docker image and then push it to ECR. Here, in this snippet I'm posting the error while building the image. This is in Window OS local machine and python version is 3.8.0

I have below folderstructure:

/home:
-->ECR
-->buildImage.py
Dockerfile

The script /home/ECR/buildImage.py looks like this:

import docker
docker_api = docker.APIClient()

    dockerfile_path = os.path.dirname(os.getcwd())
    print("Docker file location: " + dockerfile_path)
    if os.path.isfile(dockerfile_path + "\\Dockerfile"):
        print("File exists")
    else:
        print("File does not exist...")

docker_api.build(path=dockerfile_path, tag=local_tag, rm=True, dockerfile=".\\Dockerfile")

This above throws me error:

pywintypes.error: (2, 'WaitNamedPipe', 'The system cannot find the file specified.')

and with this one,

docker_api.build(path='dockerfile_path', tag=local_tag, rm=True, dockerfile=".\\Dockerfile")

this throws me

TypeError: You must specify a directory to build in path

How can I fix this? Is it necessary that on your local machine which in my case in Window Docker should be available? Docker is not installed but docker python package version 4.1.0 is installed.

print(docker.__version__)
>> 4.1.0
1
  • 1
    You need to have docker installed locally as well. Commented Dec 17, 2019 at 15:32

1 Answer 1

1

You need to have the Docker Engine installed as well. This is a Python API for the Docker Engine, so it is just using the source code from your local Docker through a python interface. Furthermore, your version of API needs to match your Docker engine SDK.

From the docs:

Versioned API and SDK


The version of the Docker Engine API you should use depends upon the version of your Docker daemon and Docker client.

A given version of the Docker Engine SDK supports a specific version of the Docker Engine API, as well as all earlier versions. If breaking changes occur, they are documented prominently.

Daemon and client API mismatches

  • The Docker daemon and client do not necessarily need to be the same version at all times. However, keep the following in mind.

  • If the daemon is newer than the client, the client does not know about new features or deprecated API endpoints in the daemon.

  • If the client is newer than the daemon, the client can request API endpoints that the daemon does not know about."

Sign up to request clarification or add additional context in comments.

4 Comments

thanks got it. Since this my window machine and it will be pain. So I moved to machine where docker engine is installed. How can I make sure my python api is compatible with docker engine? python docker version is 4.1.0 while linux2 machine both engine and client version is 1.39 and on DOcker 18.09.9-ce. Now if I run the script it shows me ` File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 498, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', error(104, 'Connection reset by peer'))`
Look at the doc link I posted. There is a table on the bottom which shows which api is compatible with which docker. You can pip install a specified version of the api consistent with your docker version.
thanks again. I have gone thru the links and everything is compatible. but I think, It's working now, it's just the way I was referring the location is not right. But now im able to build it. If anyone wants reference pypi.org/project/docker is great help.
Glad to hear you got it resolved. If this was helpful consider giving it an upvote, and if it answered your question click the green check mark to indicate that for future visitors to the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.