Docker hub:
First, clone image training application from github
created a dockerfile with multistaged
next, built an image
signed into dockerhub official application
Did port mapping
docker tag trainapp:latest upen1992/train:2.0
docker push upen1992/train:2.0
Madhu can pull image from my dockerhub
docker run -d --name containername -p 8080:8080 upen1992/train:2.0
Dockerpull - dockerhub to local
Dockerpush - myimage pushing to dockerhub
Docker entrypoint and CMD:
vi Dockerfile
629 docker images
630 docker build -t image1:lts .
631 docker images
632 docker run -it --name cont-1 image1:lts
633 docker ps -a
634 docker run -it --name cont-2 --entrypoint="echo" image1:lts hi madhu
635 docker ps -a
636 vi Dockerfile
637 docker build -t image2:lts .
638 docker run -it --name cont-3 image2:lts
639 docker ps -a
640 cat Dockerfile
641 history
docker commit
create a dockerfile
docker commit cont-4 image3:lts
docker public repository - Registry? Volumes
docker run -d --name registry -p 5000:5000 registry
649 docker ps
650 docker container inspect registry
651 curl localhost:5000/v2/_catalog
652 docker images
653 docker tag image3:lts localhost:5000/image3:lts
654 docker push localhost:5000/image3:lts
655 curl localhost:5000/v2/_catalog
656 docker images
657 docker container inspect registry
658 docker volume ls
659 docker ps -a
660 docker rm -f registry
661 docker run -it --name dummy -p 5000:5000 registry
662 curl localhost:5000/v2/_catalog
663 docker rm -f dummy
664 docker run -it --name registry -p 5000:5000 -v
fdc31c9dfe212382a979a9867a64c6a6f6b4ea0d1fb6d60ad1298f513befbacf:/var/lib/registry
registry
665 curl localhost:5000/v2/_catalog
666 history
Volumes Explanation:
Mysql:
docker run -it --name mysql -e MYSQL_ROOT_PASSWORD=rootpass -p 3306:3306 mysql
< docker exec -it mysql mysql -u root -p > Then enter the password (rootpass). >
SHOW DATABASES; > create database madhu; > create database upendra; > use madhu >
show databases; > docker inspect mysql > check volume bottom as source
/var/lib/docker/volumes >
curl localhost as follow the bottom registry.
Attach volume: docker run -it --name mysql -v inspect longlink mentioned as
name :/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=rootpass mysql > docker
exec -it mysql mysql -u root -p > show databases;
Registry:
Bind Volume(mount volume) - I have a image3 indefault
cd/ > ls > mnt > sudo su > mkdir demo >ls > docker run -it --name registry -p
5000:5000 -v /demo:/var/lib/registry
> Registry will create > docker ps > curl localhost 5000/v2/_catalog > docker push
localhost:5000/images3:lts > ls > cd demo/ >cd docker/ >cd registry > ls> cd v2> cd
repositories/ > ls > docker rm -f registry > docker ps -a > docker run -d --name
pradeep -p 5000:5000 -v /demo:/var/lib/registry registry
> curl localhost:5000/v2/_catalog
1. Shared volume
docker ps > docker run -it --name cont1 -v my-volume ubuntu > ls > Myvolume should
be created > echo "This is from Cont1" > file1 > ls > cat file1 > ctrl p+1 > docker
run -it --name cont2 --privileged=true --volumes-from cont1 alpine sh > cd my-
volume > ls > echo "this is from cont2" >> file1 > cat file1 > docker exec -it
cont1 bash > cd my-volume/ >
2. Docker Network
docker ls > 3 types of netwoks
Check: ifconfig = etho is host machine
docker 0 = docker hypervisor
loop back is lo
docker run -it --name cont2 ubuntu > ctrl p+q > ifconfig > veth is avaiable(docker
allocated bridge network) > docker inspect bridge > check container 2 as it's
allocated internally in docker inspect as default in bridge network
3. Null network --> docker run -it --name demo --network none ubuntu > apt install
> apt udate > it will show the error.
4. Host network --> docker run -it --name cont4 --network host ubuntu > It will try
to replace the host ip >docker inspect > ip will get overlap
5. Bridge network --> docker inspect > no containers as I have deleted all the
containers > create container > docker run -it --name cont1 ubuntu > docker inspect
bridge > let me create anohter container > docker run -it name cont2 ubuntu >
container inspect > copy the cont1 ip from inspect > docker exec -it cont2 bash >
ping ip > ping not found > apt install nettools > apt update > apt install net-
tools > ping ip > ping not found > apt install by checking chat gpt > ping ip > It
should communicate from one to another computer > both the containers in one
network >
Let's create a mynetwork in docker
docker network mynetwork --subnet=11.11.0.0/16 > docker network ls > now creating
container --docker run -it --name cont3 --network mynetwork ubuntu >apt update >
apt install iputils-ping > ping 172.17.0.2 > docker inspect mynetwork > docker
network connect bridge cont3 > lets move to container 3 > docker exec -it cont3
bash > ping 172.17.0.2 > Now, lets disconnect > docker network disconnect bridge
cont3 > docker exec -it cont3 bash > ping 172.17.0.2 > now it's
docker run -it --name upendra nginx - to give the name
docker attach upendra --> go inside the container
Touch f1 --> create a file and insert the content
docker system prune -a - To delete all the images and containers except running
containers (Not Recommended)
docker export upendra > sanjay.tar.gz
docker import sanjay.tar.gz myimage
docker rm upendra - I have remove the container
it's stored as myimage and create a new container using rahul.
docker run -it --name rahul myimage
docker run -it --name rahul myimage:latest /bin/bash
verify with ls
docker inspect image1:lts - to check the metadata
docker run -it image1:lts - to create a container
docker run -it image1:lts - docker save
docker load -i pradeep.tar.gz - loaded the image as backup using tarfile.ls
Copy
cp index.html madhu:/ - copying index file to madhu container in root.
docker exec -it madhu /bin/bash - switching to container and creating file and the
same file needs to copied to present path docker cp madhu:/file1 .
How to create a file without moving inside the container ?
docker exec container-name touch /tmp/file2
How to check the file content without moving inside the container?
docker exec madhu cat /tmp/file3
Entrypoint
cmd and entrypoint made it open
docker run -it --entrypoint="ls" deepa:latest -a
or
docker run -it --entrypoint="echo" deepa:latest Hi Rahul