fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@@ -0,0 +1,17 @@
---
title: Docker build
---
## Docker build
`docker build` created a docker image from a Dockerfile and a "context". A context can be a URL or a local PATH. You can name the image using the optional `-t` tag.
A Dockerfile will install dependencies during the build command, from a specified URL or local PATH. Any dependencies necessary in your containers must be specified in the Dockerfile.
Your image is now stored in your machines local Docker image registry.
When you have Docker containers built, you can then run your app using the appropriate run commands.
#### More Information:
- [Docker CLI docs: build](https://docs.docker.com/engine/reference/commandline/rm/)
- [Docker Building Your App](https://docs.docker.com/get-started/part2/#build-the-app)

View File

@@ -0,0 +1,50 @@
---
title: Docker compose
---
## Docker compose
Docker-Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your applications services.
The steps to use docker-compose are
```
1)create a Dockerfile which defines the image and can be produsable every where.
```
```
2)create a docke-compose yml file to run the services
```
```
3)use docker-compose up to start the sevices specified in docker-compose.yml file
```
#### Basic commands in docker-compose
* Command to run docker-containers
```
docker-compose -f docker-compose.yml up
```
* Command to run containers in detached mode
```
docker-compose -f docker-compose.yml up -d
```
* command to run containers after buildingthe images again(note: first time we run docker containers build will happen automatically)
```
docker-compose -f docker-compose.yml --build -d
```
* Command to stop containers when we run in detached mode
```
docker-compose -f docker-compose.yml down
```
#### More Information:
- [More information on Docker-compose]
(https://docs.docker.com/compose/)

View File

@@ -0,0 +1,18 @@
---
title: Docker detached mode
---
## Docker detached mode
Detached mode, shown by the option `--detach` or `-d`, means that a Docker container runs in the background of your terminal. It does not receive input or display output.
```
docker run -d IMAGE
```
If you run containers in the background, you can find out their details using `docker ps` and then reattach your terminal to its input and output.
#### More Information:
- [Attach to and detach from a running container | Docker Docs](https://docs.docker.com/engine/reference/commandline/attach/#examples)
- [Detached vs foreground | Docker docs](https://docs.docker.com/engine/reference/run/#detached-vs-foreground)

View File

@@ -0,0 +1,28 @@
---
title: Docker kill
---
## Docker kill
`docker kill` kills one or more running Docker containers by names or IDs.
The basic usage is:
```
docker kill mycontainer
```
Or with container ID:
```
docker kill 769b9341d937
```
To kill more than one container, container names or IDs must be added with a whitespace character between them:
```
docker kill mycontainer mysecondcontainer mythirdcontainer
```
#### More Information:
- [Docker CLI docs: kill](https://docs.docker.com/engine/reference/commandline/kill/)

View File

@@ -0,0 +1,24 @@
---
title: Docker load
---
## Docker load
`docker load` restores a Docker image from a tar archive.
It is mostly used in conjunction with `docker save` command to transfer a Docker image without using Docker Hub or another registry.
To load an image from a file named `nginx-backup.tar`, the following command can be run:
```
docker load -i nginx-backup.tar
```
This command also recognizes gzip, bzip2 and xz compression, and decompresses the file automatically. Therefore, it can be used even without decompressing manually:
```
docker load -i nginx-backup.tar.gz
```
#### More Information:
- [Docker CLI docs: load](https://docs.docker.com/engine/reference/commandline/load/)

View File

@@ -0,0 +1,34 @@
---
title: Docker pull
---
## Docker pull
`docker pull` downloads images from Docker Hub or other Docker registries.
For example, to download the latest nginx image, the command should be run like this:
```
docker pull nginx
```
This intrinsically assumes the image associated with `latest` tag. To download a specific version, the version info must be added to the image name with a colon:
```
docker pull nginx:1.15.5
```
Docker images can also be downloaded from registries other than Docker Hub by adding the registry address in front of image name:
```
docker pull myregistry.example.com/myapplicationimage
```
Or with a specific version:
```
docker pull myregistry.example.com/myapplicationimage:1.2.11
```
#### More Information:
- [Docker CLI docs: pull](https://docs.docker.com/engine/reference/commandline/pull/)

View File

@@ -0,0 +1,25 @@
---
title: Docker rm
---
## Docker rm
`docker rm` removes containers by their name or ID.
When you have Docker containers running, you first need to stop them before deleting them.
- Stop all running containers: `docker stop $(docker ps -a -q)`
- Delete all stopped containers: `docker rm $(docker ps -a -q)`
### Remove multiple containers
You can stop and delete multiple containers by passing the commands a list of the containers you want to remove. The shell syntax `$()` returns the results of whatever is executed within the brackets. So you can create your list of containers within this to be passed to the `stop` and `rm` commands.
##### Here is a breakdown of docker ps -a -q
- `docker ps` list containers
- `-a` the option to list all containers, even stopped ones. Without this, it defaults to only listing running containers
- `-q` the quiet option to provide only container numeric IDs, rather than a whole table of information about containers
#### More Information:
- [Docker CLI docs: rm](https://docs.docker.com/engine/reference/commandline/rm/)

View File

@@ -0,0 +1,28 @@
---
title: Docker rmi
---
## Docker rmi
`docker rmi` removes images by their ID.
To remove the image, you first need to list all the images to get the Image IDs, Image name and other details. By running simple command `docker images -a` or `docker images`.
After that you make sure which image want to remove, to do that executing this simple command `docker rmi <your-image-id>`. Then you can confirm that image has been removed or not by list all the images and check.
### Remove multiple images
There is a way to remove more than one images at a time, when you want to remove multiple specific images. So to do that first get Image IDs simply by listing the images then execute simple followed command.
`docker rmi <your-image-id> <your-image-id> ...`
Write Images IDs in the command followed by the spaces between them.
### Remove all images at once
To remove all images there is a simple command to do that. `docker rmi $(docker images -q)`
Here in the above command, there are two command the first which execute in the `$()` is shell syntax and returns the results whatever executed in that syntax. So in this `-q- is a option is used to provide to return the unique IDs, `$() returns the results of image IDs and then `docker rmi` removes all those images.
#### For More Information:
- [Docker CLI docs: rmi](https://docs.docker.com/engine/reference/commandline/rm/)

View File

@@ -0,0 +1,22 @@
---
title: Docker save
---
## Docker save
`docker save` stores a Docker image to a tar archive. It is useful to make an offline backup of an image or transfer an image to a computer in a corporate environment which does not have a direct access to the Internet.
For example, to save the nginx image already in local computer to a file named `nginx-backup.tar`, the following command can be run:
```
docker save -o nginx-backup.tar nginx
```
Or with a specific version:
```
docker save -o nginx-backup.tar nginx:1.15.5
```
#### More Information:
- [Docker CLI docs: save](https://docs.docker.com/engine/reference/commandline/save/)

View File

@@ -0,0 +1,36 @@
---
title: Docker
---
## Docker
Docker is an open platform to build, ship, and run distributed applications. It is written in Go. It was first released in 2013 and is developed by Docker, Inc.
Docker is used to run packages called "containers". Containers are isolated from each others and from the OS. These are more lightweight than virtual machines as they do not use the host machine to run an operating system.
Containerization, which is a way of deploying and running applications, runs isolated services which run natively on the Linux kernel. Memory can be set manually for each container in Docker.
Docker is used to simplify configurations, and ensure a smooth continuous integration and deployment flow. Specific containers can be specified for development, staging, and production environments. A true implementation of a container in production, according to the Docker manual, is to run it as a service, using the `docker-compose.yml` file for setup. This is a YAML file that defines how Docker containers should behave in production.
One of Docker's biggest advantages is that it can be used by a team using different operateing systems to build projects without needing to worry about software conflicts.
### Installation
* Ubuntu: `sudo apt install docker`
* RedHat: `yum install docker-ce`
* Windows / macOS: [Download](https://www.docker.com/get-started)
* Linux:
```
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
```
#### More Information:
* For download and documentation check the docker official site: [Docker official site](https://www.docker.com)
* For more on containerization, checkout [Search IT Operations](https://searchitoperations.techtarget.com/definition/application-containerization-app-containerization)
* A Docker 101 course [Docker 101](https://github.com/docker/labs/tree/master/beginner/)

View File

@@ -0,0 +1,82 @@
---
title: Separate Build Image
---
## Overview
Making lightweight docker images is key to having a fast development/deployment pipeline. For compiled code, building the binary inside a docker container has the benefit of being a repeatable and standardised build process. However, this can create a very large images which can become an issue down the line.
## Our code
In this example, we will use a simple webserver writen in [Go](https://golang.org/). The following code is just a simple hello world webserver listening on port `8080`.
```go
package main
import (
"fmt"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello world!")
}
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
```
### Dockerfile
The Dockerfile for this code might look something like this
```
FROM golang:1.11
ADD . /app
WORKDIR /app
RUN go build -o /myserver .
EXPOSE 8080
CMD [ "/myserver" ]
```
Building this image results in an image with a size of 783MB!! With an image that size for a simple application, it's easy to see how this can slow things down when deploying.
## A better solution
A better solution would be to use a separate build image to build the binary and then copy it to the final image. As Go generates a standalone binary, we can use the `scratch` docker image as a base which is about as small as it gets!
### Dockerfile
The following Dockerfile will first build the binary inside the golang image and then build a new image from scratch, copying the binary from the first image into the second.
```
FROM golang:1.11 as build
ADD . /app
WORKDIR /app
RUN go build -o /myserver .
FROM scratch
COPY --from=build /myserver /myserver
EXPOSE 8080
CMD [ "myserver" ]
```
Building from this dockerfile results in a final image size of only 6.55MB! That's over **100 times smaller** than our first attempt, making it 100 times faster to pull the image down from a registry!
### Bonus benefit
Not only do we now have a tiny docker image for our application, we also only have to worry about the security of our application as there is no other software running inside the container.