Summary:
In this article we will learn about Docker Build, Pull and Run command. When you run, “docker run -d -it <container-name> <image:tag>” command, docker demon search local registry for specified “Image with tag”. If the Image is found, a new container is created with the image.
However, if the Image is not found in local registry, docker demon will search Docker Hub for the image in the Public Repository (& Private Registry as well if you are logged into Docker Hub account from the client machine). Once the specified Image is found on Docker Hub, it is Pulled into the client machine in local repository. New container is created from with the image
We can also Build Images using Docker File (with custom configuration)
Prerequisite
Create a Docker Hub account:
Create 2 Repository, Private and Public
Private Registry: ashmisinha–priv
Public Registry : ashmi_sinha2019
![](https://azmachina.com/wp-content/uploads/2021/07/2-1024x160.jpg)
Docker Architecture:
![](https://azmachina.com/wp-content/uploads/2021/07/1-1024x595.jpg)
—-
BUILD
Steps to ‘BUILD’ Docker Image for Docker Swarm Visualizer (NodeJS Image: stefanscherer/node-windows:latest)
- Copy Complete Docker Swarm Visualizer files to C:\Users\JimmyCater\docker-swarm-visualizer-master
https://github.com/dockersamples/docker-swarm-visualizer
- Edit Docker File, ‘Dockerfile.windows’ with following lines:
FROM stefanscherer/node-windows:latest
- Rename ‘Dockerfile.windows’ to ‘Dockerfile’ (Remove other Docker File to Desktop)
![](https://azmachina.com/wp-content/uploads/2021/07/3-1024x80.jpg)
- Run following command in the PowerShell:
docker build -t visualizer:latest
- New Docker Images will be created:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
visualizer latest 412ba112590e 12 minutes ago 462MB
mcr.microsoft.com/windows/servercore/iis latest a753087f34dc 3 weeks ago 3.87GB
mcr.microsoft.com/windows/nanoserver 1809-amd64 9e7d556b2b51 4 weeks ago 251MB
stefanscherer/node-windows latest 46b86f7ea7e6 3 months ago 352MB
PUSH
Steps to ‘PUSH’ Images to Docker Hub Repository:
- Login to the Docker Hub Account from any Host:
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: user-name
Password: xxxxxxxxx
Login Succeeded
- Create new Tag for Images for Image IDs: afa9d75a343e | 6c3630785aa2
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ashmisinha profile afa9d75a343e 7 days ago 5.2GB
visualizer latest 6c3630785aa2 12 days ago 462MB
docker tag 6c3630785aa2 ashmisinha/ashmi_sinha2019:visualizer-1809
docker tag afa9d75a343e ashmisinha/ashmisinha-priv:portfolio
- Upload these images to Docker Hub Repository
Push Image with Tag, ‘visualizer-1809’ to public repository, ‘ashmisinha/ashmi_sinha2019’
docker push ashmisinha/ashmi_sinha2019:visualizer-1809
Push Image with Tag, ‘portfolio‘ to private repository, ‘ashmisinha/ashmisinha-priv’
docker push ashmisinha/ashmisinha-priv:portfolio
- Login to the DockerHub and validate Images in Public and Private Repository
- Private Repository
1 Image with Tag, ‘portfolio’
![](https://azmachina.com/wp-content/uploads/2021/07/4-1024x531.jpg)
- Public Repository
1 Image with Tag, ‘visualizer-1809’
![](https://azmachina.com/wp-content/uploads/2021/07/5-1024x544.jpg)
- Search Docker Hub for Image: ashmi_sinha2019
- Docker Hub
![](https://azmachina.com/wp-content/uploads/2021/07/6-1024x320.jpg)
- Host
docker search ashmi_sinha2019
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ashmisinha/ashmi_sinha2019 Docker Images for Windows 2019 1809 0
Note: Images in the Private Repository is not available on Docker Hub Public search
docker search ashmisinha-priv
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
PULL
Steps to ‘PULL’ Images to Docker Hub Repository:
- Search Docker Hub for Images and search for Repository: ashmi_sinha2019
![](https://azmachina.com/wp-content/uploads/2021/07/7-1024x339.jpg)
- To download Image, ‘visualizer-1809’, switch to ‘Tag’ and copy Docker Pull Command for Image, ‘visualizer-1809’
![](https://azmachina.com/wp-content/uploads/2021/07/8-1024x244.jpg)
3. On Host, run Docker Pull command to download image, ‘visualizer-1809’
docker pull ashmisinha/ashmi_sinha2019:visualizer-1809
visualizer-1809: Pulling from ashmisinha/ashmi_sinha2019
Digest: sha256:35bf30679c4bd2e050081f53f9aa8e233c6303aa7adcd4b083b683093e9d1b55
Status: Downloaded newer image for ashmisinha/ashmi_sinha2019:visualizer-1809
docker.io/ashmisinha/ashmi_sinha2019:visualizer-1809
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ashmisinha/ashmi_sinha2019 visualizer-1809 6c3630785aa2 13 days ago 462MB
Note: You will not be able to search for Images in Private Repository
RUN
Steps to ‘RUN’ Container with Image: visualizer-1809
- Create Container, ‘visualizer’ with Image, ‘ashmisinha/ashmi_sinha2019:visualizer-1809′
docker run -d -p 8080:80 -e DOCKER_HOST=${ip}:2375 --name=visualizer ashmisinha/ashmi_sinha2019:visualizer-1809
c93997c979df00067949a62a0812563013862a2e09cc6a3df104eddfe1fcbc74
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c93997c979df ashmisinha/ashmi_sinha2019:visualizer-1809 “npm.cmd start” 5 seconds ago Up 3 seconds (health: starting) 8080/tcp, 0.0.0.0:8080->80/tcp visualizer
- Filter the Container for .NetworkSettings.Networks.nat.IPAddres
docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" visualizer
172.28.xx.xx
- Open Browser and type following as URL: 172.28.xx.xx:8080 to access visualizer web console