Basic insights of Docker

TEJOMAY SAHA
2 min readMay 17, 2018

What is Docker?

Docker is a virtual linux based environment to help the developers giving a flexibility to use their project setup anywhere.It has two important component i. image, ii.container .

We can use docker hub (hub.docker.com) to save(push ) or retrieve(pull) images and run it to create a container.Docker hub is the official docker image repo containing numerous images for a lot of different linux based configuration.Some of them are official and has reliable support.Remember one thing , your local environment where docker runs is host m/c and the docker running containers are virtual m/c.

Installation:

go to https://www.docker.com and get docker as per os like linux,mac , windows.Install it and after that check with docker command in terminal

basic commands:

  1. docker login (to login to hub.docker.com a/c and push/pull images)
  2. docker ps (show currently running container)
  3. docker ps -a(show all containers including exited ones)
  4. docker images (to show images installed/downloaded to your system)
  5. docker build . (to build docker image from current Dockerfile annoted with ‘.’ here)
  6. docker run -it docker-image-name:tag bash (to run a particular docker image and go shell)
  7. we can add flags like -v ,-t respectively to mount volumes and share ports between host m/c and virtual m/c.
  8. docker exec -it container_id bash (to go to current_container’s bash shell)
  9. docker stop container_id (to stop container from running)
  10. docker rm container_id( to remove docker container)
  11. docker start container_id (to start exited container)
  12. docker pull image_name:tag (to pull any image from hub.docker.com to local m/c)
  13. docker commit -m “message” container_id (to create a new image from current container to save the updated configuration)
  14. docker tag new_image_id docker_hub_repo_image_name:tag(tagging new image id with docker-hub repo image_name with a tag/version)
  15. docker push docker_hub_repo_image_name:tag(to push tagged image to docker hub repo of this repo_name:tag)

holy shit!It’s too much. I need an easy way and cool too.

OK!I see.Done

follow bellow steps only:

  1. install docker and run from command line ‘docker pull ubuntu:16.04’ or ubuntu.(ref 11.)
  2. run ‘docker run -v host_vol:virtual_vol -it ubuntu:16.04 bash’ .it will open a new bash shell(ref 6.)
  3. install your needed servers ,tools there and commit changes and push new image to hub.docker.com.
  4. before that create an a/c in hub.docker.com, and create a repo.
  5. to check running container id before commit , run from another host shell command docker ps. get the id and use docker commit -m “message” container_id.now a new image is created.run docker images ,scroll up and grab new image_id.(ref 12.)
  6. now you need to tag this image with a docker hub repo name like, ‘docker tag image_id docker_hub_repo_name:tag’.(ref 13.)
  7. push it to docker hub like ‘docker push docker_hub_repo_name:tag’.(ref 14.)
  8. next time use just pull it from any m/c with the docker_hub_repo_name:tag.

you are in heaven!!!

--

--

TEJOMAY SAHA

I am a lead engineer who loves to learn, share, explore life differently