Docker Part -4 (Docker hub and docker volume )
- Docker hub
- Docker Volume
what is Dockerhub →
As you are now a devops engineer you must knew about github that is centrilised placed for all written codes docker hub is similiar to github docker hub is centrilised location for imges
There is no. of latest images of Ubuntu ,python,busybox ,httpd etc… are present which you could fetch by command
- Docker search <image name>
- Docker pull <image name>
and you are also able to push your customized image to docker hub which you can use later for various purpose
Steps to push image to docker hub →
- First you need to have an account on dockerhub just sign up and create your account
2. you need to create a public repo which you could use to push images
go to repositories option → click on create repo
3. now back to your terminal and pull any of the image let’s say ubuntu by command
Docker pull ubuntu
4. Now create a container from image
docker run -it — name aakib ubuntu /bin/bash
now you are inside a container make a file changes by →cat > changes and then exit from container
5. Now create image of existing container by command →
docker commit <container id> <image name >
6. Now login to docker hub →docker login
If you login Successfully you have a message login succeed
7. Before you can push an image to Docker Hub, you need to tag it with your Docker Hub username and the desired repository name.
docker tag local-image-name username/repository:tag
local-image-name= image name
username =dockerhub username
tag = what you want to be
and then push your image to dockerhub by command
docker push username/repository:tag
8. verify it by going to your dockerhub and select the repo where you psuhed the image
This is all about dockerhub let’s move to docker volumes
What is Docker Volumes →
- Volume is simply a directory inside our container
- First we have to declared this directory as a volume and then share volume
- Even if we stop container still we can access volume
- Volume will be created in one container
- You can declare a directory as a volume while creating container
- You can’t create volume from existing container
- You can share volume to any number of container
- Volume will not be included venue update an image
- You can mapped volume in two ways
- Container to container
2. Host to container
Benefits of volume →
- Decoupling container from storage → Even if we delete a container with a connected volume, the volume continues to exist independently, storing our data safely.
- Share volume among different containers
- Attach volume to multiple containers
- On deleting container volume does not delete
Create Volume from dockerfile
vim dockerfile and write the above content
create an image of your dockerfile by above command
now run a container of your image and go inside to your container
by running ls you could see a directory called my volume