Debug School

Vipul Bisht
Vipul Bisht

Posted on

Docker Day 2 Assignment By Vipul Bisht

On Day 2, we got to learn about belows commands and how to create the docker image and create a tarball and push the image to the docker hub repo for public accessing by anyone .
• cp
• diff
• rename
• port
• update
• wait
• logs
• events
• top
• inspect

Docker commands for images

• docker images
• docker pull
• docker info
• docker rmi
• docker inspect
• docker commit – m “message” – a”name” container id alias name

How to design docker image

docker run -itd ubuntu
docker exec -it “containerid” /bin/bash
install java
apt-get update
apt-get install openjdk-11-jdk -y
apt-get install openjdk-11-jdk-headless -y
install apache
apt-get install apache2 -y
Install wget
apt-get install wget -y
Install war file
wget https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war
chmod 755 sample.war
commit the image

docker commit -m"message" -a"Revour_Vipul" containerid name
docker images

  • Validate java and apache docker exec containerid java docker exec containerid which apache2 docker exec containerid ls /opt/
  • Saving and loading tar file After committing the docker image
  • Save the file docker save -o image.tar name of image You can stop the containers if u want
  • Load the file docker load -i image.tar ### Docker Images: Docker image is a collection of filesystes(Root FS(which also includes the user FS) + Application FS). When creating a container all layers if image are merged together and are mounted to the container. /var/lib/docker(this can be found in docker info command) is the path to get the info of the file system layers associated with image. Inorder to save the changes done(Like adding new files/folders, changing existing ones) to a container in the form of an image, we can use commit command docker commit -m "commit message" -a "author name" container_id new_name_of_the_image This command commits all the changes done to the container given in the command to a new image. docker history new_name_of_the_image: To check what are the changes done on top of existing image, we can use history command on the committed image. To save the image as a tar, docker save -o name.tar name_of_image

To load the image which is saved as tar,
docker load -i name.tar:
Check the images using docker images command to see if the tar is loaded.

To share an image with larger group of people then tar is not a feasible option, so we push the image to a docker registry from where everyone can access the image.
Steps:

docker login -> Login to the registry.(should have created an account prior)
tag the docker image according to the repository created in your registry. The name of docker image is the repository and we will face errors while pushing if the repository we specified doesn't exist. docker tag my_image revour/demo_1 -> This tags my_image which is in my local to revour/demo_1(repository name in registry)
docker push revour/demo_1 -> push to Registry
We can validate the same using docker pull revour/demo_1 -> this should pull your image from registry.

Top comments (0)