-
Notifications
You must be signed in to change notification settings - Fork 10
/
docker-notes.txt
125 lines (90 loc) · 4.29 KB
/
docker-notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
docker system info #Display system-wide information of docker engine
#Image creation and running
docker build -t static-nginx:v0 . #building an image
docker run --rm -it -p 8060:80 static-nginx:v0 #running an container in intractive mode
docker run --rm -dt -p 8060:80 static-nginx:v0 #running an container in background
docker exec -it <container_id> /bin/sh #SSH into container
docker restart <container_id> #Restart a container
docker ps -a #listing all running containers
docker images # listing all the images
docker system prune -af #cleaning the Docker engine
docker system df #Check docker daemon disk space usage
docker stats #Show running container stats
#docker registry
docker login #docker hub login
docker build -t bhanu/static-nginx:v1.0 . # building an image with tag
docker image push bhanu/static-nginx:v1.0 #pushing an image to docker hub
docker search bhanu/static-nginx # searching an image in docker hub
docker pull bhanu/static-nginx:v1.0 #pulling an image from docker hub
# docker commit
#pull ubuntu default image
docker pull ubuntu
#check the images
docker images
# run ubuntu image in intractive mode
docker run -it <image_id_ubuntu> bin/bash
#now you are inside the container run following commands in container to install nmap
apt update
apt-get install nmap
#check nmap version
nmap --version
#exit the container
exit
#check the ID of exited container
docker ps -a
#commit ans tag the container into an image
docker commit c0989a370320 bhanu/ubuntu-nmap:v0
#push the image in docker registry
docker push bhanu/ubuntu-nmap:v0
#docker diff
docker diff <container id>
#docker network
docker network ls
#default bridge network
# Start an nginx container, give it the name 'mynginx' and run in the background
docker run --rm --name mynginx --detach nginx
# Get the IP address of the container
docker inspect mynginx | grep IPAddress
# Run busybox (a utility container). It will join the bridge network
docker run -it busybox sh
# Fetch the nginx homepage by using the container's IP address
wget -q -O - 172.17.0.2:80
#create network
docker network create tulip-net
#create nginx container in custom network
docker run --rm --net tulip-net --name tulipnginx -d nginx
#create a busy box container in the custom network
docker run --net tulip-net -it busybox sh
#calling nginx container
wget -q -O - tulipnginx:80
#For containers to communicate with other, they need to be part of the same “network”.
#Docker creates a virtual network called bridge by default, and connects your containers to it.
#In the network, containers are assigned an IP address, which they can use to address each other.
#If you want more control (and you definitely do), you can create a user-defined bridge, which will give you the added benefit of hostnames for your containers too.
# Docker volume
cd docker2
docker build -t static-nginx-nofiles:v0 .
docker run --rm -it -p 8060:80 static-nginx-nofiles:v0
docker run --rm -it -v <PATH\html_files>:/usr/share/nginx/html -p 8060:80 static-nginx-nofiles:v0
D:\technical_work\repos\docker-session\html_files
docker run --rm -it -v D:\technical_work\repos\docker-session\html_files:/usr/share/nginx/html -p 8060:80 static-nginx-nofiles:v0
docker volume create data_volume
docker volume ls
docker volume inspect data_volume
docker volume rm data_volume
docker volume prune
docker run -v data-volume:/var/opt/project bash:latest bash -c "ls /var/opt/project"
docker run -v data-volume:/var/opt/project bash:latest bash -c "echo Baeldung > /var/opt/project/Baeldung.txt"
docker run -v data-volume:/var/opt/project bash -c "ls /var/opt/project"
docker run --mount 'type=volume,src=data-volume,dst=/var/opt/project,volume-driver=local,readonly' bash -c "ls /var/opt/project"
#Differences between -v and --mount behavior
#As opposed to bind mounts, all options for volumes are available for both --mount and -v flags.
#When using volumes with services, only --mount is supported.
#Docker ports
#ingress
#ingress controller example
helm upgrade --install ingress-nginx ingress-nginx --repo https://kubernetes.github.io/ingress-nginx --namespace ingress-nginx --create-namespace
#Check the Ingress controller pod is running
kubectl get pods --namespace ingress-nginx
#Check the NGINX Ingress controller has been assigned a public Ip address
kubectl get service ingress-nginx-controller --namespace=ingress-nginx