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)