Description: Here I have explained, How to create a custom image from the running container and upload it to Docker Hub in Public Repository.
Create Base Container: First I am going to create a base container, here I am using httpd container and creating some custom page in the apache path.
- Pull httpd image from docker hub and verify after pulling from docker hub
# docker pull httpd
- Create a container using httpd image and verify after running the container
# docker run -td httpd
- After creating the container, Rename the container from a unique name using the docker rename command
# docker rename peaceful_hermann httpd_servertech
- Add some custom pages on http path in the container. Enter into the container using the below command
# echo "This is test page from servertechnolab" > index.html
Under the path of /usr/local/apache2/htdocs
Create Image from Running container: After creating and modifying the container, I am going to create an image from the running container.
- First, verify container images using the below command
# docker images
- Commit the container using the below command
- Tag the image using below command
Push the image to Docker Hub: After creating the image, now I am going to push it to the docker hub
Login to docker hub using below command
# docker login
It will popup for username and password of docker hub
Commit Docker Image: Commit docker image using docker commit command
# docker commit -m="This is httpd custom image" httpd_servertech harpalgohilon/opensource
Here,
-m="This is httpd custom image": This is a commit message
httpd_servertech = the name of the container, from which you created the image
harpalgohilon/opensource = Name of the docker hub repository where you want to push the image.
Push the Image to Docker Hub: Now I am going to push the image to docker hub
# docker push harpalgohilon/opensource
After Upload you will get your image under docker repository
Change the Tag of image from latest to httpd
# docker tag harpalgohilon/opensource:latest harpalgohilon/opensource:httpd
No comments:
Post a Comment