-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTOPICS-LAB.txt
More file actions
141 lines (105 loc) · 3.61 KB
/
TOPICS-LAB.txt
File metadata and controls
141 lines (105 loc) · 3.61 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
================================================================================
DOCKER
================================================================================
docker --version
docker version
docker info
docker run hello-world
docker image ls
docker container ls
docker container ls --all
docker container ls -aq
docker container kill <hash> # Force shutdown of the specified container
docker container rm <hash> # Remove specified container from this machine
docker container rm $(docker container ls -a -q) # Remove all containers
--- DOCKERFILE -----------------------------------------------------------------
mkdir myproj
cd myproj
--------------------------------------------------------------------------------
cat << EOF > Dockerfile
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
EOF
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
cat << EOF > requirements.txt
Flask
Redis
EOF
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
cat << EOF > app.py
from flask import Flask
from redis import Redis, RedisError
import os
import socket
# Connect to Redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)
app = Flask(__name__)
@app.route("/")
def hello():
try:
visits = redis.incr("counter")
except RedisError:
visits = "<i>cannot connect to Redis, counter disabled</i>"
html = "<h3>Hello {name}!</h3>" \
"<b>Hostname:</b> {hostname}<br/>" \
"<b>Visits:</b> {visits}"
return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80)
EOF
--------------------------------------------------------------------------------
docker build -t friendlyhello .
docker image ls
docker run -p 4000:80 friendlyhello
docker run -d -p 4000:80 friendlyhello
curl http://localhost:4000
docker container stop 4f2366509714
--- DOCKER HUB -----------------------------------------------------------------
docker login
docker tag friendlyhello devopslab01/get-started:part2
docker image ls
docker push devopslab01/get-started:part2
--- DOCKER COMPOSE -------------------------------------------------------------
docker-compose --version
--------------------------------------------------------------------------------
cat << EOF > docker-compose.yml
version: "3"
services:
web:
# replace username/repo:tag with your name and image details
image: devopslab01/get-started:part2
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "4000:80"
networks:
- webnet
networks:
webnet:
EOF
--------------------------------------------------------------------------------
docker swarm init
docker stack deploy -c docker-compose.yml getstartedlab
docker service ps getstartedlab_web
docker stack rm getstartedlab
docker swarm leave --force