forked from pradeepch82/docker-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
/
day3.txt
270 lines (155 loc) · 5.94 KB
/
day3.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
Day3
====
1.Docker Image Creation
2.Docker Container Linking
3.Docker Compose
4.docker volumes
Creating the Images
====================
1.From running Containers
=========================
docker run --name p-apache -d -p 9999:80 httpd
docker exec -it p-apache bash
echo "<h1>Hello Welcome To Custom Apache Image</h1>" > /usr/local/apache2/htdocs/index.html
docker commit -m 'Index File Content Changed' -a 'Pradeep Chinchole <[email protected]>' p-apache pradeepch82/apache:1.1
docker login
username :[email protected]
password :password
docker push pradeepch82/apache:1.1
docker run --name b-apache -p 4545:80 -d pradeepch82/apache:1.1
2.Using Docker File
====================
Dockerfile :
A text file with instructions to build image
Automation of Docker Image Creation
FROM :Base Image
MAINTAINER :Author Name
ENV :Environment variable
ADD :ADD the files while buiding the image
RUN :To install libraries/packages (executed while building the image)
ENTRYPOINT :Executed at run time and we can not override the commands
CMD :Executed at run time and we can override by passing command line argument
Step 1 : Create a file named Dockerfile
Step 2 : Add instructions in Dockerfile
Step 3 : Build dockerfile to create image
Step 4 : Run image to create container
Example :Dockerfile
FROM ubuntu
MAINTAINER Pradeep Chinchole <[email protected]>
RUN apt-get update
CMD ["echo", "Hello World..! from my first docker iamge1"]
CMD ["echo", "Hello World..! from my first docker iamge2"]
CMD ["echo", "Hello World..! from my first docker iamge3"]
CMD ["echo", "Hello World..! from my first docker iamge4"]
COMMANDS
: docker build directoryOfDocekrfile
: docker build -t ImageName:Tag directoryOfDocekrfile
: docker run imageid
docker build -t pradeepch82/pvc-ubuntu:1.1 .
docker run pradeepch82/pvc-ubuntu:1.1 .
Docker file for MYSQL
======================
# Derived from official mysql image (our base image)
FROM mysql
# Add a database
ENV MYSQL_DATABASE company
ENV MYSQL_ROOT_PASSWORD admin
ENV MYSQL_USER pradeep
ENV MYSQL_PASSWORD pradeep
# Add the content of the sql-scripts/ directory to your image
# All scripts in docker-entrypoint-initdb.d/ are automatically
# executed during container startup
ADD script.sql /docker-entrypoint-initdb.d/
script.sql
===========
use company;
create table employee(id int primary key,name text,salary double);
insert into employee values(101,'RAM',10000.00);
insert into employee values(102,'RAHIM',20000.00);
insert into employee values(103,'DAVID',30000.00);
insert into employee values(104,'PRADEEP',40000.00);
docker build -t pradeepch82/pvc-mysql:1.1
https://www.javatpoint.com/docker-java-example
https://www.javatpoint.com/docker-php-example
https://www.javatpoint.com/docker-phython-example
https://www.javatpoint.com/docker-scala-example
https://www.javatpoint.com/docker-perl-example
https://www.javatpoint.com/docker-ruby-example
Linking the containers (mysql with WordPress)
==================================================
docker network create p-network
docker run --name p-mysql --network p-network -e MYSQL_ROOT_PASSWORD=admin -e MYSQL_DATABASE=wordpress -d mysql:5.7
docker run --name p-wordpress --network p-network --link p-mysql -e WORDPRESS_DB_HOST=p-mysql:3306 -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_PASSWORD=admin -e WORDPRESS_DB_NAME=wordpress -p 1111:80 -d wordpress
Open browser: http://hostname:1111
docker stop p-wordpress p-mysql
docker rm p-wordpress p-mysql
docker network rm p-network
Linking the containers (mysql with WordPress) using docker-compose
====================================================================
docker-compose.yml
=====================
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
docker-compose up -d
docker-compose --scale db=4
docker-compose down
Docker Volumes
===============
1. What are Volumes
2. How to create / list / delete volumes
3. How to attach volume to a container
4. How to share volume among containers
5. What are bind mounts
Volumes are the preferred mechanism for persisting data generated by and used by Docker containers
docker volume //get information
docker volume create
docker volume ls
docker volume inspect
docker volume rm
docker volume prune
Use of Volumes
===================
Decoupling container from storage
Share volume (storage/data) among different containers
Attach volume to container
On deleting container volume does not delete
Commands
For MySQL
============
docker volume create myvol
docker run --name a-mysql -v myvol:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=company -d mysql:5.7
docker run --name b-mysql -v myvol:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
docker exec -it b-mysql bash
root@9e2af2d31b2d:/# mysql -uroot -proot
For Jenkins
============
docker run --name MyJenkins1 -v myvol2:/var/jenkins_home -d -p 8080:8080 -p 50000:50000 jenkins
docker run --name MyJenkins2 -v myvol2:/var/jenkins_home -d -p 9090:8080 -p 60000:50000 jenkins
http://hostname:8080
Default username :admin
Password :Copy from MyJenkins Container logs (docker logs MyJenkins1)
http://hostname:9090