0% found this document useful (0 votes)
20 views9 pages

Docker Enn End

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views9 pages

Docker Enn End

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Docker ene-end

In this we learn about


1. Containers
2. Diff b/w VM and Docker
3. Installation
4. Commands
5. More on container developing
6. Docker compose-how to run multiple services
7. Docker file
8. Docker repo
9. Docker hub and Making private repo
10. Volumes
Containers are the artifacts that comes with dependicies,packages with applications and can
be easily moved,shared and it will a container repository(Eg:-Public repo is Docker hub).
Containers are running environments where we run image then it will become container.
To access a container we need a port to connect port and

 Docker run -p6000(Hostport):6379(port that we see in ps) imagename


 To remove container
 docker rm container name or id
 To remove image
 docker rmi image name or id

Debugg and Troubleshhoting in Docker:

 To debug or troubleshoot we need to know about logs.


 To see the logs of the container
Docker logs containerid or name

 To give a specific name


Docker run -d -p6000:6379 --name Egname imagename
 To check into container for trouble shooting
Docker exec -it containerid /bin/bash
Docker Networking:
1. Bridge
2. Host
3. Overlay
4. None
5. Macvlan
1.Network device (Ens 160)
2.Bridge(172.17.0.1/16or12or17or20)we can also create additional bridges.
3.1.virtual Ethernet 2.virtual Ethernet 3.Virtual Ethernet.

Working with Default Bridge:


Docker network ls
We can see bridges
Docker run -dit --name kiran1 redis
Docker run -dit --name kiran2 redis
We can see 2 containers with names kiran1 nd kiran2 of redis image
Docker network inspect bridge

 To exit from the container with stoping contain


Ctrl p and ctrl q

Creating Custom Bridge Network


Docker network create --driver bridge kiran-net
Docker network inspect kiran-net

 To add a container with custom bridge


Docker run -dit –-name kaka --network kiran-net(bridgename)
imagename
Docker run -dit –-name kaka2 --network kiran-net imagename
Docker run -dit –-name kaka3 --network bridge imagename
Docker run -dit –-name kaka --network bridge imagename
Docker network connect bridge kaka3

Now
Docker network inspect bridge
You kaka in kiran-net and default bridge
You can attach kaka3 and can also ping kaka because they are in same
bridge
Docker attach kaka3
Ping kaka

Storage Solutions:
1. Bind Mount
2. San
3. Persistent
4. Tmpfs
5. Cow
/etc/docker/daemon.json

Cowtest strategy:
1. mkdir cowtest
2. vi hello
Hello
3. chmod +x hello
4. vi dockerfile.base
FROM ubuntu:20.04
COPY . /app
5. vi dockerfile
FROM Koe/base-image:1.0
CMD /app/hello.sh
6. docker build -t Koe/base-image:1.0 -f dockerfile.base .
7. docker build -t Koe/final-image:1.0 -f dockerfile .
8. docker image ls
9. docker history imageid of baseimage
10.docker history imageid of finalimage
we can see finalimage on top.

How to create container storage using


bindmount
 Bindmount is storage that also bind on linux machine
 Whatever you do on host files there will be change in containers also

Mkdir bind1
Echo bound > bind1/bond.txt
Cd bind1
Ll
We can see bond.txt file in bind1

Create file

Docker run –-rm -dit –-name=bind1 –-mount type=bind,source=”$


(pwd)”/bind1,target=/app redis:latest

Docker exec bind1 ls -l /app


Echo hello > bind1/hello.txt
Docker exec bind1 ls -l /app
We can see bond.txt and hello.txt files
Docker exec bind1 touch /app/ttt.txt
Docker exec bind1 ls -l /app
We can see 3files in bind1 container and if go our host directory and
check we can see those 3files and this known as bind mounts.

Or instead of –-mount we can use -v

Docker run –-rm -dit –-name=bind2 -v ”$(pwd)”/bind1:/app redis:latest


Docker exec bind2 ls -l /app

Here we bounded the bind2 image with the bind1 then the files in bind1
also will be presented in bind2.

How to use volumes for persistent storage:


 Volume will be persistent till container life
 Can access multiple containers at same time
 Can store data externally.(sandbox or cloud).

To create a docker volume


Docker volume create volumename
Docker volume inspect volumename
You can see like mountpoints

Creating a container with running volume


Docker run -it –-name volumetest –-rm –-mount source=kiranvol,target=/data
redis:latest /bin/sh
Cp /etc/hosts /data
Touch /data/blabla
Ctrl p&q
Cd mountppoint path
Ls
You can see the hosts and blabla file.

To run another container with same volume.

Docker run -it –-name volumetest2 –-rm –-mount source=kiranvol,target=/data


redis:latest /bin/sh
Ls /data
Hosts blabla
You can see same files in the volumetest2 container which were in volumetest1

To access multicontainers through volume we need to use drivers

Docker run -it –-name volumetest –-rm –-mount


source=kiranvol,target=/data,readonly redis:latest /bin/sh

By adding readonly we can protect from mountlock


We can also use nfs and create local drivers
Apt install nfs-server nfs-common

Mkdir /nfsdata
Vi /etc/exports
/nfsdata *(rw,no_root_squash)
Chown nobody:nogroup /nfsdata
Chmod 777 /nfsdata/
Systemctl restart nfs-kernel-server
Systemctl status nfs-kernel-server
Showmount -e localhost
We can see /nfsdata

Docker volume create --driver local –-opt type=nfs –-opt


o=addr=127.0.0.1,rw --opt device=:/nfsdata nfsvolume

Docker volume ls
Docker volume inspect nfsvolume

To make any inputs in container

Docker run -it –-name nfstest –-rm –-mount source=nfsvolume,target=/data


redis:latest /bin/sh
Cd /data/
Touch hahaha
Ctrl p&q
Docker volume inspect nfsvolume
Cd mountpointpath(which will be in inspection)
Ll
You can see the hahaha file

Docker Compose
Whenever we are going to run multiple containers we use docker compose

Docker network create mongo-network


Docker run -d -p 27017:27017 -e
MONGO_INITDB_ROOT_USERNAME=admin -e
MONGO_INITDB_ROOT_PASSWORD=password --name mongodb –-net
mongo-network mongo
And we run another container

Docker run -d -p 8081:8081 -e


ME_CONFIG_MONGODB_ADMINUSERNAME=admin -e
MONGO_CONFIG_MPNGODB_ADMINPASSWORD=password -e
ME_CONFIG_MONGODB_SERVER=mongodb –-name mongo-express –-net
mongo-network mongo-express

Now we run multiple containers to make it compose file


Mongo-docker-compose.yaml
Version:3
Services:name of the container
Image: Mongo
Ports:
Environment:MONGO-USERNAME=admin
Network

Create a vi docker-compose.yaml

Docker-compose -f docker-compose.yaml up

Docker File
Vi dockerfile
Docker build -t devapp:1.0(Eg)

You might also like