Skip to content

Commit 034708e

Browse files
committed
added code and command samples for docker
1 parent 385642d commit 034708e

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed

Diff for: a-crash-course-on-docker/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM nginx:alpine
2+
VOLUME /usr/share/nginx/html
3+
EXPOSE 80

Diff for: a-crash-course-on-docker/README.md

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
![a rather large whale](https://cdn-images-1.medium.com/max/2000/1*GQ6CAclmEnGe7PX4pg6sSA.jpeg)
2+
3+
# A crash course on Docker
4+
5+
The quick start guide you are looking for.
6+
You can take a look at the full article [here]() (issue #1, add article title once published).
7+
8+
## TL;DR
9+
- "Why I need this?"
10+
- Quick Start
11+
- Real-life scenario
12+
13+
## "Why I need this?"
14+
- What is Docker?
15+
- What is a VM?
16+
- What is CaaS?
17+
- Using automation
18+
19+
## Quick Start
20+
- Installation
21+
22+
**Ubuntu**
23+
```bash
24+
$ sudo apt-get update
25+
$ sudo apt-get install -y docker-ce
26+
$ sudo systemctl status docker
27+
28+
29+
// output //
30+
31+
● docker.service - Docker Application Container Engine
32+
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
33+
Active: active (running) since Sun 2018-01-14 12:42:17 CET; 4h 46min ago
34+
Docs: https://docs.docker.com
35+
Main PID: 2156 (dockerd)
36+
Tasks: 26
37+
Memory: 63.0M
38+
CPU: 1min 57.541s
39+
CGroup: /system.slice/docker.service
40+
├─2156 /usr/bin/dockerd -H fd://
41+
└─2204 docker-containerd --config /var/run/docker/containerd/containerd.toml
42+
```
43+
44+
If the system service is stopped.
45+
```bash
46+
$ sudo systemctl start docker && sudo systemctl enable docker
47+
```
48+
49+
Run Docker without **sudo**
50+
```bash
51+
$ sudo usermod -aG docker ${USER}
52+
$ su - ${USER}
53+
$ id -nG
54+
```
55+
If you see your username is the list of usernames, you're set.
56+
57+
**Mac**
58+
Download and install.
59+
- https://docs.docker.com/docker-for-mac/install/
60+
61+
**Windows**
62+
Download and install.
63+
- https://docs.docker.com/docker-for-windows/install/
64+
65+
66+
- Create a container
67+
```bash
68+
$ docker create -it ubuntu:16.04 bash
69+
```
70+
71+
- List all containers
72+
```bash
73+
$ docker ps -a
74+
75+
// output //
76+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
77+
7643dba89904 ubuntu:16.04 "bash" X min ago Created name
78+
```
79+
80+
- Start a container where in this case `7643dba89904` is the `<container_id>`
81+
```bash
82+
$ docker start 7643dba89904
83+
```
84+
85+
- List only running containers
86+
```bash
87+
$ docker ps
88+
```
89+
90+
- Connect to a container
91+
```bash
92+
$ docker attach 7643dba89904
93+
```
94+
95+
- Delete a container
96+
```bash
97+
$ docker rm 7643dba89904
98+
```
99+
100+
## Real-life scenario
101+
102+
- Create a container and bind a volume to the host machine
103+
- In this case it will bind the current working directory from the host machine where you run the command in the terminal
104+
```bash
105+
$ docker create -it -v $(pwd):/var/www ubuntu:latest bash
106+
```
107+
108+
- Create and start a container with a single command
109+
- `-d` flag tells the container to run detached, in the background, meaning you can go ahead and attach to it right away.
110+
```bash
111+
$ docker run -it -d ubuntu:16.04 bash
112+
```
113+
114+
- Stop a running container
115+
```bash
116+
$ docker stop <container_id>
117+
```
118+
119+
### Using the config files
120+
- Check out the **Dockerfile**, **docker-compose.yml**, and the **index.html**.
121+
122+
#### Build an image from a **Dockerfile**
123+
```bash
124+
$ docker build . -t webserver:v1
125+
```
126+
127+
- List created Docker images
128+
```bash
129+
$ docker images
130+
```
131+
132+
### Run the created image
133+
```bash
134+
$ docker run -v $(pwd):/usr/share/nginx/html -d -p 8080:80 webserver:v1
135+
```
136+
137+
#### Run with docker-compose
138+
- The `-d` signals docker-compose to run detached, then you can use `$ docker-compose ps` to see what’s currently running, or stop docker-compose with `$ docker-compose stop`.
139+
```bash
140+
$ docker-compose up (-d)
141+
```
142+
143+
144+
### Deleting images and containers
145+
```bash
146+
$ docker rmi <image_id>
147+
$ docker rm <container_id>
148+
```
149+
150+
Happy Dockering! :D

Diff for: a-crash-course-on-docker/docker-compose.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '2'
2+
3+
services:
4+
web:
5+
build: .
6+
ports:
7+
- "8080:80"
8+
volumes:
9+
- .:/usr/share/nginx/html

Diff for: a-crash-course-on-docker/index.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<html>
2+
<head>
3+
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-MfvZlkHCEqatNoGiOXveE8FIwMzZg4W85qfrfIFBfYc= sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
4+
<title>Docker Quick Start</title>
5+
</head>
6+
<body>
7+
<div class="container">
8+
<h1>Hello Docker</h1>
9+
<p>This means the nginx server is working.</p>
10+
</div>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)