Home:ALL Converter>Can a Dockerfile push itself to a registry?

Can a Dockerfile push itself to a registry?

Ask Time:2017-07-17T19:52:38         Author:James

Json Formatter

For the use case where a Dockerfile needs to be built for each platform it's on (a bit niche I know), is there a way possible for it to push itself to the registry, i.e. calling docker push from within the Dockerfile?

Currently, this is done:

docker build -t my-registry/<username>/<image>:<version> .
docker login my-registry
docker push <image>

Could the login and push steps be directly or cleverly built into the Dockerfile being built or with a combination of others?

Note: This would operate in a secure environment of trustworthy users (so all users being able to push to the registry is fine).

Note: This is an irregular use of Docker, not a good idea for building/packaging software in general, rather I am using Docker to share environments between developers.

Author:James,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/45143567/can-a-dockerfile-push-itself-to-a-registry
so-random-dude :

I am wondering why can't you have a wrapper script file (say shell or bat) around the \"Dockerfile\" to do these steps\n\ndocker build -t my-registry/<username>/<image>:<version> .\ndocker login my-registry\ndocker push <image>\n\n\nWhat is it so specific about \"Dockerfile\". I know, this is not addressing the question that you asked, I might have totally misunderstood your usecase, but I am just curious.\n\nAs others pointed out, this can be easily achieved using a CD systems like Drone.io/Travis/Jenkins etc.\n\nAt first this sounds to me like the decently-circulated \"Nasa's Space pen Myth\". But as I said earlier, you may have a proper valid use case which I am not aware of yet.",
2017-07-17T17:49:10
Eanlr :

Docker build creates image using recipe provided in Dockerfile. Each line in Dockerfile creates new temporary image of file system with different checksum. Image after execution of last line of Dockerfile is your final image of build process and is tagged with provided name.\n\nSo it is not possible to put docker push command inside Dockerfile because image creation is not finished yet.",
2017-07-17T13:06:08
yy