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,127 @@
# Useful commands for Docker
- Docker is mainly used for run programs on server side.
- Companies customize their OS before use. They don't require many things like GUI.
- Less program means less RAM used and more security.
- More features means more chances to hack, more vulnerabilities.
- We use OS to run program. Docker gives us an environment to run our program.
## Installing docker-engine
### For Redhat OS
- First, setup yum repo
```
[docker]
baseurl = https://yum.dockerproject.org/repo/main/centos/7
gpgcheck=0
```
- Then, install **docker-engine**
`$ yum install docker-engine`
### Start the services of docker
`$ systemctl restart docker`
It starts the docker server.
### See all the images available in docker
`$ docker images`
The default _docker images_ will show all top level images, their repository and tags, and their size.
### Load an image in docker
`$ docker load -i ubuntu-14.04.tar`
- **i** - Read from tar archive file, instead of STDIN
It loads an image or repository from a tar archive (even if compressed with gzip, bzip2, or xz) from a file or STDIN. It restores both images and tags.
### Docker run reference
- Docker runs processes in isolated containers.
- A container is a process which runs on a host. The host may be local or remote.
- When an operator executes `docker run`, the container process that runs is isolated in that it has its own file system, its own networking, and its own isolated process tree separate from the host.
### Run or start a new OS
`$ docker run -it ubuntu:14.04`
- The `docker run` command first `creates` a writeable container layer over the specified image, and then `starts` it using the specified command.
- The above example runs a container using the `ubuntu:14.04` image. The `-it` instructs Docker to allocate a pseudo-TTY connected to the containers stdin; creating an interactive `bash` shell in the container.
### See all the running OSs
`$ docker ps`
- The `docker ps` command only shows running containers by default.
- To see all containers, use the `-a` (or `--all`) flag:
`$ docker ps -a`
### Come out from docker OS console
`exit`
### From shell of docker OS, for coming out without exiting container
press _ctrl + p + q_
### From terminal of base system, to run a command in docker OS
`$ docker exec mycontainer ifconfig`
- **mycontainer** is the name of container.
- The `docker exec` command runs a new command in a running container.
### Usually run docker using this command
`$ docker run dit ubuntu:14.04`
- **i** - interactive
- **t** - terminal
- **d** - detach
### Stop all running OSs
```
$ docker ps -q //shows id of every running OS
$ docker stop $(docker ps -q)
```
### Permanently remove a container
`$ docker rm id`
### Permanently Remove all the stopped containers
`$ docker rm $(docker ps -a -q)`
- This command will delete all stopped containers.
- The command `docker ps -a -q` will return all existing container IDs and pass them to the `rm` command which will delete them.
- Any running containers will not be deleted.
### Remove containers while running (forcefully)
`$ docker rm -f $(docker ps -a -q)`
### Giving docker OS a name when starting
- By default, docker gives unique name to every container with a unique id.
- We can also give a name to container using following command -
`$ docker run -it --name adarsh centos:latest`
### Copy a file in container
`$ docker cp /root/form.txt myconatiner:/`
This command will copy a file form.txt from the base system to the specified container.
### Download docker images
[docker hub](http://hub.docker.com) - All the available docker images can be downloaded from this URL.
### Check different versions of OS that are available
```
$ docker search ubuntu //search
$ docker pull ubuntu:17.10 //downlaod required version
```
## Docker Storage
### Basic Storage types
1. **Empheral disk (temporary)** OS removal will remove data (like windows C drive)
2. **Persistent disk (permanent)** - OS removal will not erase data (like windows D drive)
- **-v** gives persistent storage. OS removal will not remove data.
### Docker volume manager
Docker by default takes space from **/** drive of host system to store data. Overall **/** drive amount of storage docker can use.
### Give separate space to a docker container
- Make a partition, format it and mount in base system.
Let the partition created is **mypart**
- Then, run following command
`$ docker run it -v /mypart:/data centos`
- **mypart** is a partition in base system and **data** is the folder where docker will store it's data.
- **v** - volume
### Attaching dvd to a container
`$ docker run it v /run/media/root/RHEL-7.3\ Server.. centos`
This command will attach a RHEL to the container.
### Copy content from a folder of base system to _/data_ in docker centos
`$ docker run it -v /folder_name:/data centos`

View File

@@ -0,0 +1,14 @@
---
title: Creating a new container
---
Creating a container using Docker CLI
```yaml
docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
```
# Examples
Create and start a container
```sh
$ docker create -t -i fedora bash
```

View File

@@ -0,0 +1,74 @@
# Running Web Server inside Docker
### Start docker and its container -
```
$ systemctl restart docker
$ systemctl enable docker
$ docker run -it --name webserver centos:latest
```
### Install httpd
- **yum** is already configured in centos docker image.
So directly install **httpd** software -
`$ yum install httpd -y`
- Create a dummy web page to check the server -
```
$ cd /var/www/html
$ vi index.html
```
### Start services -
- If we use **systemctl** to start the services, this will not work and gives an error.
- **systemctl** doesn't work in docker.
- In actual RedHat system, when we start a service it actually runs a script in background. That script start daemons.
- To find the path of that script, check status of service
`$ systemctl status httpd`
`Loaded` option shows script file path.
- In that file, we have a line which actually starts service -
`ExecStart = /usr/sbin/httpd....... `
So the command `/usr/sbin/httpd` actually starts **httpd** server.
- Service is running or not, can be checked by -
`$ ps -aux | grep httpd`
- So we don't require `systemctl` we can directly start our web server using-
`$ /usr/sbin/httpd`
This will start the web server.
- `ifconfig` doesn't work in docker.
- So install software, which gives `ifconfig` command.
- It can be checked in actual Redhat system by running this command-
`$ rpm -qf /usr/sbin/ifconfig`
- This comes from **net-tools** package.
- So Install **net-tools** in docker os.
- Making _image_ of created web server -
`$ docker commit webserver apacheimg:v1`
- Name of container is _webserver_.
- This image can be share with exact setup with other users.
- To save created image -
`$ docker save apacheimg:v1 -o mywebserver.tar`
- To start **httpd** service automatically when container starts -
- Write `/usr/sbin/httpd` in following file.
`$ vim /root/.bashrc`
- To copy a file in container from the base system -
`$ docker cp /root/form.txt myconatiner:/`
## Summary
Summary of all the commands -
```
$ docker run -it --name webserver centos:latest
$ yum install httpd -y
$ rpm -q httpd
$ cd /var/www/html
$ vi index.html
// write some web content
$ /usr/sbin/httpd
$ yum install net-tool
$ ifconfig
```

View File

@@ -0,0 +1,35 @@
---
title: Docker
---
## Docker
[Docker](https://www.docker.com/) is a widely-used container platform available for Linux, Windows, and Mac, as well as cloud providers like AWS and Azure.
A common use case would be to package an app and all it's requirements in a container. The container can then be used during development, passed to quality assurance/testing, and on to production/operations. This eliminates the "works on my machine" mentality, as the container effectively _is_ the machine, no matter what actual hardware it may be running on.
After you are done setting up your computer and installig docker, you can simply test your Docker by running command:
```shell
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
```
If you have no hello-world image locally Docker will automatically download it to your machine.
You can list image that was downloaded or created to your machine by running command:
```shell
$ docker image ls
```
[Docker Store](https://hub.docker.com/explore/) contains many common applications packaged up into containers and ready to be used.
## Further reading
* [Docker Documentation](https://docs.docker.com)

View File

@@ -0,0 +1,52 @@
---
title: Containers
---
## Containers
Containers are a solution to the problem of how to get software to run reliably when moved from one computing environment to another.This could be from a developer's laptop to a test environment, from a staging environment into production, and perhaps from a physical machine in a Data Center to a Virtual machine in a Private or Public cloud.
In other words, a Container consists of an entire runtime environment: an application, plus all its dependencies, libraries and other binaries, and configuration files needed to run it, bundled into one package. By containerizing the application platform and its dependencies, differences in OS distributions and underlying infrastructure are abstracted away.
Containers are an operating-system-level virtualization - an operating system feature in which the kernel allows the existence of multiple isolated user-space instances. Such instances, called containers may look like real computers from the point of view of programs running in them.
## Virtual Machines
A VM is essentially an emulation of a real computer that executes programs like a real computer. VMs run on top of a physical machine using a “hypervisor”. A hypervisor, in turn, runs on either a host machine or on “bare-metal”.
A *hypervisor* is a piece of software, firmware, or hardware that VMs run on top of. The hypervisors themselves run on physical computers, referred to as the “host machine”. The host machine provides the VMs with resources, including RAM and CPU. These resources are divided between VMs and can be distributed as you see fit. So if one VM is running a more resource heavy application, you might allocate more resources to that one than the other VMs running on the same host machine.
The VM that is running on the host machine (again, using a hypervisor) is also often called a “guest machine.” This guest machine contains both the application and whatever it needs to run that application (e.g. system binaries and libraries). It also carries an entire virtualized hardware stack of its own, including virtualized network adapters, storage, and CPUwhich means it also has its own full-fledged guest operating system. From the inside, the guest machine behaves as its own unit with its own dedicated resources. From the outside, we know that its a VMsharing resources provided by the host machine.
As mentioned above, a guest machine can run on either a hosted hypervisor or a bare-metal hypervisor. There are some important differences between them.
First off, a hosted virtualization hypervisor runs on the operating system of the host machine. For example, a computer running OSX can have a VM (e.g. VirtualBox or VMware Workstation 8) installed on top of that OS. The VM doesnt have direct access to hardware, so it has to go through the host operating system (in our case, the Macs OSX).
The benefit of a hosted hypervisor is that the underlying hardware is less important. The hosts operating system is responsible for the hardware drivers instead of the hypervisor itself, and is therefore considered to have more “hardware compatibility.” On the other hand, this additional layer in between the hardware and the hypervisor creates more resource overhead, which lowers the performance of the VM.
A bare metal hypervisor environment tackles the performance issue by installing on and running from the host machines hardware. Because it interfaces directly with the underlying hardware, it doesnt need a host operating system to run on. In this case, the first thing installed on a host machines server as the operating system will be the hypervisor. Unlike the hosted hypervisor, a bare-metal hypervisor has its own device drivers and interacts with each component directly for any I/O, processing, or OS-specific tasks. This results in better performance, scalability, and stability. The tradeoff here is that hardware compatibility is limited because the hypervisor can only have so many device drivers built into it.
After all this talk about hypervisors, you might be wondering why we need this additional “hypervisor” layer in between the VM and the host machine at all.
Well, since the VM has a virtual operating system of its own, the hypervisor plays an essential role in providing the VMs with a platform to manage and execute this guest operating system. It allows for host computers to share their resources amongst the virtual machines that are running as guests on top of them.
## Container
Unlike a VM which provides hardware virtualization, a container provides operating-system-level virtualization by abstracting the “user space”. Youll see what I mean as we unpack the term container.
For all intent and purposes, containers look like a VM. For example, they have private space for processing, can execute commands as root, have a private network interface and IP address, allow custom routes and iptable rules, can mount file systems, and etc.
The one big difference between containers and VMs is that containers *share* the host systems kernel with other containers.
## Orchestration
There are several container orchestration frameworks leveraged in production: docker-swarm and kubernetes
## List of container providers
Bellow is a small list of the most used containers vendors that can be used.
- [Docker](https://www.docker.com/)
- [Kubernetes](https://kubernetes.io/)
- [Amazon AWS ECS](https://aws.amazon.com/ecs/?nc1=h_ls)
- [RKT](https://github.com/rkt/rkt)
- [Azure Fabric](https://azure.microsoft.com/en-us/services/service-fabric/)

View File

@@ -0,0 +1,29 @@
---
title: Run Your First Docker Image
---
## Run Your First Docker Image
After you are done setting up your computer and installig docker, you can simply test your Docker by running command:
```shell
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
...
```
If you have no hello-world image locally Docker will automatically download it to your machine.
You can list image that was downloaded or created to your machine by running command:
```shell
$ docker image ls
```
More Information:
test Docker installation <a href='https://docs.docker.com/get-started/#test-docker-installation' target='_blank' rel='nofollow'>documentation</a>.