简体   繁体   中英

how does docker containerization and push to azure container registry work with given command?

I always push local docker image to azure container registry using given commands for testing:

docker build . -t [registry location].azurecr.io/[project]:SNAPSHOT-1
docker tag [registry location].azurecr.io/[project]:SNAPSHOT-1 [registry location].azurecr.io/[project]:SNAPSHOT-1
docker push [registry location].azurecr.io/[project]:SNAPSHOT-1

When I do this, it creates docker image in my local, and also in the azure container registry in [registry location] -> [project] -> SNAPSHOT-1.

I read the documentation from docker website, but just need clarification. From docker it says:

When the URL parameter points to the location of a Git repository, the repository acts as the build context. The system recursively fetches the repository and its submodules. The commit history is not preserved. A repository is first pulled into a temporary directory on your local host. After that succeeds, the directory is sent to the Docker daemon as the context. Local copy gives you the ability to access private repositories using local user credentials, VPN's, and so forth.

So it builds an image in Docker Daemon(?) in my local using Git repository build context(?) that is how I understand it.

docker tag is the one that I am not sure of. It says:

docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

Since I have same SOURCE_IMAGE and TARGET_IMAGE, what does it mean? Is SOURCE_IMAGE the image from local(?) Docker Daemon that I just built? Why is this necessary?

Lastly, I have docker push...... . Does it create image in azure container registry (acr) because I defined it in the ...... , for example, dev.azurecr.io/[project]:tag . I thought it is the docker image I built. Does it just know from the docker image tag(?) to push image to acr -> dev as tag name?

I am sorry if this are stupid questions... I have worked with docker and acr for some time, but I only know how it works but never understand how exactly what it means. Can someone please explain to me each line command in simple way? I really appreciate it!

Well, the first you need to know is that the image name and the image tag. Usually, we create the image without the container registry URL, something like image_name:tag . Actually, it means it's you only can manage the image in your local machine. When you want to pull the image in another machine, the image name will change like https://registry_url/image_name:tag . So you know, if you want to push the image to the remote registry, you need to tag the image like registry_url/image_name:tag .

And when you build the docker image, it will create the context of the image and store it in your local machine, then you push the image to remote registry, it means you copy the image context into the remote registry.

Finally, be honest, you don't need the second command. The first and the third are enough. The first create the docker image context in your local machine, and the third push the image into the ACR.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM