-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocker_notes
More file actions
177 lines (128 loc) · 4.59 KB
/
Copy pathdocker_notes
File metadata and controls
177 lines (128 loc) · 4.59 KB
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
Docker architecture :
=====================
Docker follows Client-Server architecture, which includes the three main components that are Docker Client, Docker Host, and Docker Registry.
Docker Networking :
===================
Using Docker Networking, an isolated package can be communicated. Docker contains the following network drivers -
Bridge - Bridge is a default network driver for the container. It is used when multiple docker communicates with the same docker host.
Host - It is used when we don't need for network isolation between the container and the host.
None - It disables all the networking.
Overlay - Overlay offers Swarm services to communicate with each other. It enables containers to run on the different docker host.
Macvlan - Macvlan is used when we want to assign MAC addresses to the containers.
Docker Storage :
================
Docker Storage is used to store data on the container. Docker offers the following options for the Storage -
Data Volume - Data Volume provides the ability to create persistence storage. It also allows us to name volumes, list volumes, and containers associates with the volumes.
Directory Mounts - It is one of the best options for docker storage. It mounts a host's directory into a container.
Storage Plugins - It provides an ability to connect to external storage platforms.
Docker Useful Commands :
========================
$ docker version
$ docker build -t image-name docker-file-location
$ docker run -itd image-name
$ docker images
$ docker ps -l
$ docker ps -a
$ docker stop container_id
$ docker rmi image-name
$ docker rmi $(docker images -q)
$ docker rmi -r $(docker images -q) --> forecefully removes all images
$ docker rm $(docker ps -a -q) --> removes all containers
$ docker exec -it container-id bash --> to connect into container
Docker Push Repository :
========================
1. login to your registry. ex: hub.docker.com
docker login -u username -p password
2. tag your image
docker tag image-name username/image-name
3. push docker image
docker push username/image-name
Docker compose :
================
It is a tool which is used to create and start Docker application by using a single command. We can use it to file to configure our application's services.
It is a great tool for development, testing, and staging environments.
It provides the following commands for managing the whole lifecycle of our application.
Start, stop and rebuild services
View the status of running services
Stream the log output of running services
Run a one-off command on a service
To implement compose, it consists the following steps.
Put Application environment variables inside the Dockerfile to access publicly.
Provide services name in the docker-compose.yml file so they can be run together in an isolated environment.
run docker-compose up and Compose will start and run your entire app.
A typical docker-compose.yml file has the following format and arguments.
// docker-compose.yml
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
- logvolume01:/var/log
links:
- redis
redis:
image: redis
volumes:
logvolume01: {}
Installing Docker Compose :
$ curl -L https://github.com/docker/compose/releases/download/1.12.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose --version
Running Application using Docker Compose :
$ mkdir docker-compose-example
$ cd docker-composer-example
$ vim app.py
from flask import Flask
from redis import Redis
app = Flask(__name__)
redis = Redis(host='redis', port=6379)
@app.route('/')
def hello():
count = redis.incr('hits')
return 'Hello World! I have been seen {} times.\n'.format(count)
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
:wq
$ vim requirements.txt
flask
redis
:wq
$ vim Dockerfile
FROM python:3.4-alpine
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
:wq
$ vim docker-compose.yaml
version: '2'
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
redis:
image: "redis:alpine"
:wq
$ docker-compose up
Output : verify output in your browser at 0.0.0.0:5000
Sample Dockerfile :
FROM ubi8
MAINTAINER <name,email>
WORKDIR /usr/local/bin
ENV KOPS_VERSION=1.21.3
ARG KUBECTL_VERSION=1.4
RUN yum update -y && \
yum install -y wget jq && \
wget <--URL--for--KOPS--> && \
chmod +x kops && \
curl <--url--for--kubectl-latest--> && \
chmod +x kops
COPY ./dependency .
ENTRYPOINT [ "yum", "install", "-i" ]
CMD [ "git" ]