My Documents
My Documents
Aim :To perform Docker commands with push and pull commands.
Theory:
To Build your own Docker Image
1. Write a docker file
#mkdir mydockerbuild (create a directory named mydockerbuild)#cd mydockerbuild (go to
directory created above)#vi Dockerfile (create a new docker file using vi editor)
FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
If you see ‘no permission’ error, try to prefix above command with ‘sudo’ as shown in above
snapshot.
3. Now if you can see your latest build using ‘docker images’ command
#docker images
If you are programmer or in some way related to coding or software world, I assume that you
must be aware of GitHub. Similarly, there exists DockerHub.
What is DockerHub?
People all over the world create Docker images. You can find these images by browsing the
Docker Hub. In this next section, you’ll search for and find the image you’ll use in the rest of
this getting started.
What is Docker Store?
The Docker Store contains images from individuals like you and official images from
organisations like RedHat, IBM, Google, Microsoft, and a whole lot more. Each image
repository contains information about an image.
We will use our docker-whale image to push to docker hub account which you created above.
4.2 Tag the ‘docker-whale’ image using the ‘docker tag’ command and the image
ID. #docker tag <image-id of docker-whale> <your dockerhub username>/docker-
whale:latest
Now if your use ‘docker images’ command to list images, you shall see your dockerhub
username against docker-whale image as shown in above snapshot.
5. Push your tagged image to Docker Hub, using the ‘docker push’ command
7.2 Let’s remove all versions of docker-whale image on our local system
#docker rmi -f <Image ID of docker-whale>
Use ‘docker images’ command to confirm if all instances of ‘docker-whale’ has been
removed.
When you use ‘docker run’ it automatically downloads (pulls) images that don’t yet
exist locally, creates a container, and starts it. Use the following command to pull and
run the ‘docker-whale’ image, substituting your Docker Hub username.
Output:
Step 1. Create a docker Hub account
Step2: Build a demo application my-python-app by running the following commands in
command prompt
Till now we have create the my-python-app file
See if the file is working in the browser using port number
Step3: See all the images present in the docker. Here you will see that my-python-app is also
present.
Step6: Check the images present, this should include the image name with repository
Step8: Check that the images with the repository is now present in the list
Conclusion:
Built docker image with the help of python and then learned about the usage of docker image
push to share our images to the Docker Hub registry and also how to pull an image.