In this tutorial I am going to show you how to build your own image and push it back to your own Docker Repository.
Lets download Centos image from docker hub.
[root@siddhesh ~]# docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ...
latest: Pulling from docker.io/library/centos
8a29a15cefae: Pull complete
Digest: sha256:fe8d824220415eed5477b63addf40fb06c3b049404242b31982106ac204f6700
Status: Downloaded newer image for docker.io/centos:latest
[root@siddhesh ~]#
Now lets launch a container using following command in interactive mode.
[root@siddhesh ~]# docker run -it --name="centos_siddhesh" centos:latest /bin/bash
[root@951632b6d79c /]#
Now lets create couple of test directory and files under this container.
[root@951632b6d79c /]# mkdir test_sid1
[root@951632b6d79c /]# mkdir test_sid2
[root@951632b6d79c /]# mkdir test_sid3
[root@951632b6d79c /]# touch sidfile1
[root@951632b6d79c /]# touch sidfile2
[root@951632b6d79c /]# ls
bin etc lib lost+found mnt proc run sidfile1 srv test_sid1 test_sid3 usr
dev home lib64 media opt root sbin sidfile2 sys test_sid2 tmp var
[root@951632b6d79c /]#
Lets build an image using this basic changes with docker commit command.
[root@siddhesh ~]# docker commit -m="This a test image siddhesh" centos_siddhesh siddheshtechtalk/siddhesh
sha256:56b749a9604facd92e7194103af0cdabdb03591e67796b781990d5371c96a863
[root@siddhesh ~]#
You can verify newly build image. You would see the new image "siddheshtechtalk/siddhesh"
[root@siddhesh ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
siddheshtechtalk/siddhesh latest 56b749a9604f 11 seconds ago 237MB
centos latest 470671670cac 2 months ago 237MB
[root@siddhesh ~]#
Now lets push this image to your own docker hub repository. So next step is to login into the docker hub.
[root@siddhesh ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: siddheshtechtalk
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@siddhesh ~]#
Now you can push the image to the docker hub repository.
[root@siddhesh ~]# docker push siddheshtechtalk/siddhesh
The push refers to repository [docker.io/siddheshtechtalk/siddhesh]
e5d9c78375b4: Pushed
0683de282177: Mounted from library/centos
latest: digest: sha256:39ba7d05f56ceb3c3f6a4470cfb3bd875dcf1619a31503686aaa8d92c1b35681 size: 736
[root@siddhesh ~]#
Lets login to Docker hub and verify the images in Repository. You can verify this using sha256.
ความคิดเห็น