You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+48-28
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,15 @@
1
-
# Containerization: From 0 to a vizualization microservice
1
+
# Containerization: From 0 to a visualization micro-service
2
2
## (and why you shouldn't do it this way)
3
3
4
4
This is a simple tutorial on how get started with containers by deploying a visualization web application.
5
5
6
6
## Terminology
7
-
-*Image*: Executable package that contains the application
7
+
-*Image*: Executable package that contains the application
8
8
-*Container*: Running (or terminated) instance of an image, containers survive after finish. Need to delete them when done
9
9
``` docker rm $(docker ps -a -q -f status=exited) ```
10
10
-*Dockerfile*: Configuration file with the instructions to build an image
11
-
-*Docker deamon*: Background service which runs the deamon and controls the containers and images
12
-
-*Docker client*: CLI tool to access the docker service to build, deploy and delete containers
11
+
-*Docker daemon*: Background service which runs the daemon and controls the containers and images
12
+
-*Docker client*: CLI tool to access the docker service to build, deploy and delete containers
13
13
-*Docker Hub*: Docker official registry service
14
14
15
15
## Let's start with the very basic
@@ -21,12 +21,12 @@ Busybox is just a shell, nothing else:
21
21
Build a very simple html server:
22
22
23
23
docker build -t demo1 demo1/.
24
-
25
-
To run it in deamon mode use `-d` and to expose the port use `-p <PORT HOST>:<PORT INSIDE CONTAINER TO BE EXPOSED>` since this will be running nginx, by default is using port 80
26
24
27
-
docker run -d -p 8080:80 --name my-first-demo demo1
28
-
29
-
`--name` is optional. Let's see if the container based on image `demo1` is running,
25
+
To run it in daemon mode use `-d` and to expose the port use `-p <PORT HOST>:<PORT INSIDE CONTAINER TO BE EXPOSED>` since this will be running nginx, by default is using port 80
26
+
27
+
docker run -d -p 8080:80 --name my-first-demo demo1
28
+
29
+
`--name` is optional. Let's see if the container based on image `demo1` is running,
30
30
31
31
docker ps
32
32
@@ -35,38 +35,57 @@ You should see something like this:
35
35
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
36
36
cabe55ffa71f demo1 "nginx -g 'daemon ..." 2 seconds ago Up 1 second 0.0.0.0:8080->80/tcp my-first-demo
37
37
```
38
+
Then you can open your browser and go to [http://localhost:8080](http://localhost:8080)
39
+
38
40
Let's stop and delete the container
39
41
40
42
docker stop my-first-demo
41
43
docker rm my-first-demo
42
44
43
-
or you can use: `docker rm my-first-demo --force`.
45
+
or you can use: `docker rm my-first-demo --force`
46
+
47
+
You can also use jupyterlab images and run jupyter from inside a container
48
+
49
+
docker run -p 8888:8888 jupyter/base-notebook
50
+
51
+
and open your browser at [http://localhost:8888](http://localhost:8888) and copy/paste the token printed on your screen
44
52
53
+
To save the work done on the notebooks you need to mount a local volume so when the container is deleted you can still have your notebooks saved.
45
54
46
-
## Simple deployement of the application
55
+
docker run --rm -p 8888:8888 -e JUPYTER_LAB_ENABLE=yes -v $PWD/jhub:/home/jovyan/work jupyter/base-notebook
56
+
57
+
There are some interesting images in Docker Hub you can run directly, **BUT** there is also malicious images runing as root that can mess up your system. Don't copy/paste or run any images you are not sure of or you haven't seen the Dockerfile
58
+
59
+
60
+
## Simple deployment of the application
47
61
48
62
Two containers will be created, one contains a simple MySQL DB and another one a simple interactive user interface written in python, they will be linked internally.
49
63
50
64
### Deploy MySQL
51
65
52
-
To deplot locally, replace the variables in `<>`:
66
+
To deploy locally, replace the variables in `<>`:
53
67
54
-
docker run --name <NAME_MYSQL> -p <PORT>:3306 -e MYSQL_ROOT_PASSWORD=<PASSWORD> -d mysql:5.6
Now you can access in your browser at [http://localhost:8080](http://localhost:8080)
101
+
81
102
Let's get inside the container:
82
103
83
104
docker exec -it my-first-app bash
84
-
105
+
85
106
Exercise: Let's modify the `website/template/main.html` and re-deploy.
86
107
87
108
88
109
89
110
## Deployment on AWS
90
111
91
-
Using [AWS EC2](https://github.com/mgckind/container_demo.git) services
112
+
Using [AWS EC2](https://github.com/mgckind/container_demo.git) services
92
113
93
114
After deploying an EC2 instance, install docker (There are other pre-installed options, or even [Beanstalk](https://aws.amazon.com/elasticbeanstalk/)):
94
115
@@ -102,15 +123,15 @@ You can either pull a repository and build the images or use the DockeHub regist
102
123
We need to push the tag and push the images, (only webapp):
103
124
104
125
docker tag webapp mgckind/my-demo-app:1.0.0
105
-
126
+
106
127
Then we need to login to the Hub:
107
128
108
129
docker login
109
-
130
+
110
131
and push the image:
111
132
112
133
docker push mgckind/my-demo-app:1.0.0
113
-
134
+
114
135
Login to AWS, launch an instance, install docker, pull the images and repeat the steps above
115
136
116
137
In this case you need to expose 8080 to 80 and use the correct image name
@@ -121,4 +142,3 @@ In this case you need to expose 8080 to 80 and use the correct image name
121
142
## Deployment -- the less simple way but still easy
122
143
123
144
Using [Kubernetes](https://kubernetes.io/), note that GKE and AWS provide Kubernetes cluster as a Service.
0 commit comments