Browse Source

Inital commit

Jimmy Allen 1 month ago
parent
commit
9dec7341d2
1 changed files with 141 additions and 2 deletions
  1. 141 2
      README.md

+ 141 - 2
README.md

@@ -1,3 +1,142 @@
1
-# Introduction
1
+# Docker
2
+
3
+- [What is Docker](#what-is-docker)
4
+- [Why use Docker](#why-use-docker)
5
+- [How it works](#how-it-works)
6
+- [Installing Docker](#installing-docker)
7
+  - [Linux](#linux)
8
+  - [Windows](#windows)
9
+  - [Mac](#mac)
10
+- [Using Docker](#using-docker)
11
+- [Using Docker Compose](#using-docker-compose)
12
+- [Building an image](#building-an-image)
13
+- [More on Docker command usage](#more-on-docker-command-usage)
14
+  - [Container commands](#container-commands)
15
+  - [Volume commands](#volume-commands)
16
+  - [Image commands](#image-commands)
17
+  - [Network commands](#network-commands)
18
+- [More on building images](#more-on-building-images)
19
+## What is Docker
20
+Docker is program that does operation system level virtualization.
21
+It uses containers, which contain the application and all of its tools libraries and configs.
22
+Containers are isolated from each other and communicate through well define channels.
23
+All the container share a single operating system kernel. This makes the more lightweight than virtual machines. 
24
+Containers are built from and images which define what the container contains. They normally will use a publicly available base image.
25
+## Why use Docker 
26
+
27
+A great advantage of docker is that you have development environment that will be identical to the production one. It allows you to easily run multiple version of software with out them interfering with each other. You can easily share a development environment around. It supports all the major operating systems and is easy to install. It is scalable and supports high availability.
28
+## How it works
29
+
30
+There is a base operating system, be it bare metal or a virtual machine that docker is install on. Containers based of an image will then run on this system. Persistent storage, in the form of a volume or a file system mount can be added. Container run on their own internal networks and need to forward to access the outside world. 
31
+## Installing Docker
32
+
33
+### Linux 
34
+
35
+curl -fsSL curl -fsSL https://get.docker.com | sudo bash -
36
+sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose`
37
+sudo chmod +x /usr/local/bin/docker-compose
38
+
39
+### Windows
40
+
41
+https://docs.docker.com/docker-for-windows/install/
42
+
43
+
44
+### Mac
45
+
46
+https://docs.docker.com/docker-for-mac/install/#install-and-run-docker-for-mac
47
+
48
+Once it is install open a terminal and run 
49
+
50
+`docker run hello-world`
51
+
52
+---
53
+## Using Docker
54
+
55
+This will create a container with the name 'webserver' and will listen to all public interfaces on port 8080 using the nginx image.
56
+
57
+`docker run --name webserver -p 8080:80 -d nginx`
58
+
59
+Show running containers
60
+
61
+`docker ps`
62
+
63
+Show all containers
64
+
65
+`docker ps -a`
66
+
67
+Start Stop 
68
+
69
+`docker start <name/id>`
70
+`docker stop <name/id>`
71
+
72
+---
73
+## Using Docker Compose
74
+Quite often you will need multiple applications, say a web app, a webserver and a database. Managing the separately can be a pain. This is where Docker Compose is use full. It allows you combine multiple containers into stack to make the easier to manage.
75
+```
76
+version: '3'
77
+services:
78
+  nginx:
79
+    image: jwilder/nginx-proxy
80
+    ports:
81
+      - "80:80"
82
+      - "443:443"
83
+    container_name: nginx
84
+    volumes:
85
+      - /var/run/docker.sock:/tmp/docker.sock:ro
86
+      - nginx-vhost:/etc/nginx/vhost.d
87
+      - nginx-certs:/etc/nginx/certs
88
+      - nginx-html:/usr/share/nginx/html
89
+    restart: unless-stopped
90
+
91
+  letsencrypt:
92
+    image: jr
93
+    cs/letsencrypt-nginx-proxy-companion
94
+    container_name: letsencrypt
95
+    volumes:
96
+      - /var/run/docker.sock:/var/run/docker.sock:ro
97
+      - nginx-vhost:/etc/nginx/vhost.d
98
+      - nginx-certs:/etc/nginx/certs
99
+      - nginx-html:/usr/share/nginx/html
100
+    environment: 
101
+      NGINX_PROXY_CONTAINER: nginx
102
+    restart: unless-stopped
103
+    
104
+volumes:
105
+  nginx-vhost:
106
+  nginx-certs:
107
+  nginx-html:
108
+  portainer:
109
+```              
110
+## Building an image
111
+```
112
+FROM python:slim
113
+
114
+RUN pip install \
115
+    docker \
116
+    jupyter
117
+
118
+COPY docker.ipynb /data/docker.ipynb
119
+COPY *.py /data/
120
+COPY entry.sh /entry.sh
121
+
122
+RUN useradd -d /data jupyter \
123
+    && chown -R jupyter:jupyter /data
124
+
125
+EXPOSE 8888
126
+
127
+VOLUME /data
128
+
129
+WORKDIR /data
130
+
131
+ENTRYPOINT [ "sh", "/entry.sh" ]
132
+
133
+CMD [ "--ip=0.0.0.0", "--NotebookApp.token=''" ]
134
+```
135
+## More on Docker command usage 
136
+### Container commands
137
+
138
+### Volume commands
139
+### Image commands
140
+### Network commands
141
+## More on building images
2 142
 
3
-An introduction to Docker