In the previous article, I showed you how to create a customized docker image "mycoolwebsite". In this article, I will show you how to publish the image to Docker Hub and re-use it anywhere.
Note: If you intend to follow along, create a Docker Hub account and a public repository within your account.
Docker Hub images should use naming format of <dockerusername/<repository name>. In my case its "wizardonwire/mycoolwebsite"
I am going to rebuild "mycoolwebsite" image with this new name so i could push it to docker hub. You need can look at this article for DockerFile i am using.
PS C:\web> docker build -t wizardonwire/mycoolwebsite:latest .
Sending build context to Docker daemon 18.68MB
Step 1/2 : FROM httpd:2.4
---> ccbcea8a6757
Step 2/2 : COPY ./content/ /usr/local/apache2/htdocs/
---> Using cache
---> 47c1b5e7dfc1
Successfully built 47c1b5e7dfc1
Successfully tagged wizardonwire/mycoolwebsite:latest
Before I push this image to Docker Hub, I need to login to Docker Hub from the shell. This is accomplished with the "docker login" command.
PS C:\web> docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: wizardonwire
Password:
Login Succeeded
Now I can "push" the image to Docker Hub.
PS C:\web> docker push wizardonwire/mycoolwebsite:latest
The push refers to repository [docker.io/wizardonwire/mycoolwebsite]
880f25d870f2: Mounted from wizardonwire/sysspace.net
5d727ac94391: Mounted from wizardonwire/sysspace.net
4cfc2b1d3e90: Mounted from wizardonwire/sysspace.net
484fa8d4774f: Mounted from wizardonwire/sysspace.net
ca9ad7f0ab91: Mounted from wizardonwire/sysspace.net
13cb14c2acd3: Mounted from wizardonwire/sysspace.net
latest: digest: sha256:3e7f083e285df351ab59972a43d27db1b06c542ff0c8aee168afa450ba1958bf size: 1578
With the above command, the image is pushed to my repository and I can view the image by going to the repository link.
Now I am going to remove the "mycoolwebsite" image and attempt to run the container by "pulling" it from the repository with "docker run" command.
PS C:\web> docker image rm wizardonwire/mycoolwebsite
Untagged: wizardonwire/mycoolwebsite:latest
PS C:\web> docker run -detach --name webfromrepo -p 80:80 wizardonwire/mycoolwebsite:latest
And it works!!
Comments