Docker basis

Why docker? In a traditional deployment, we will encounter different machines, different versions dependent on compatibility and other issues, resolve this problem typically consume a lot of time, and have to execute the deployment of the unified environment on different machines is a lengthy work . In addition, different environments, for example, further comprising a cost managed Dev / Test / Prod like. To solve these problems, Docker should be shipped out. MongoDB online training helps you to learn more effectively.

Docker may use different operating Container different components (e.g. node.js web server, MongoDB, Messaging System, etc.), and these Containers can be run on the same physical host, while no influence on each other (i.e., each have their own execution environment dependent). Such as:

By the graph we can see, Docker Container is a shared Kernel, and executed on Docker layer. Docker and Hypervisor (the virtualization process control) is not the same: Docker is not virtual, not run different OS Kernel and on the same underlying hardware, its main purpose is to use containers of using the same set of different applications and OS Kernel execution. The traditional virtualization architecture:

This virtualization of the infrastructure will largely use of hardware resources, and the VM image is generally GB-level data. The Docker Container is a lightweight resource size is the amount of MB level. This makes Docker Container start faster, usually second level. The president of the VM starts much time, because of the need to start the entire OS.

Docker Installation and Start

In Linux, you may be used directly yum or apt-get installation, such as:

sudo yum install -y docker

Then start:

sudo /etc/init.d/docker start

test:

sudo docker run hello-world

Basic Docker command

docker run

The implementation of a docker container, specify parameters for the image name, if this image does not exist locally, it will download from dockerhub, for example:

sudo Docker RUN Ubuntu

Unable to find image ‘ubuntu:latest’ locally

latest: Pulling from library/ubuntu

7ddbc47eeb70: Pull complete

c1bbdc448b72: Pull complete

8c3b70e39044: Pull complete

45d437916d57: Pull complete

Digest: sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d

Status: Downloaded newer image for ubuntu:latest

docker ps

List the containers currently running. You can use docker ps -a to view the status of all containers.

docker stop <container_name>

Stop a docker container. But this docker container can still be docker ps -a command lists.

docker rm <container_name>

Removing a docker container.

docker images

List all images.

docker rmi <image_name>

Remove one image. Before removing the need to remove all the container is being used in this image.

docker pull

To pull a local image, performed after the docker run, you will not go DockerHub pull mirror. MongoDB training for more skills and techniques.

docker exec

Executes the specified command within a docker container. The (7e2290cbe2f7 of docker id):

docker exec 7e2290cbe2f7 cat /etc/release

DISTRIB_ID=Ubuntu

DISTRIB_RELEASE=18.04

Docker Run command Advanced

Version

1. Specify the image, such as:

docker run ubuntu:17.04

2. attach to the container in a running, such as:

docker run -d training/webapp

docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

fdd161c7d3f3 training/webapp “python app.py” 19 seconds ago Up 19 seconds 5000/tcp vibrant_hermann

docker attach eager_johnson

for outputting attach points to the current instance of the container stdout

3. docker run -i designated waiting stdin input

  1. Port Mapping

After the execution of a sample web app, we can see the following output:

docker run training/webapp

At this point, port 5000 is bound to a private network ip, for example: we look at the internal ip of container:

docker exec da16b96211f6 ifconfig

eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:02

      inet addr:172.17.0.2  Bcast:172.17.255.255  Mask:255.255.0.0

      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

      RX packets:15 errors:0 dropped:0 overruns:0 frame:0

      TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

      collisions:0 txqueuelen:0

      RX bytes:1186 (1.1 KB)  TX bytes:0 (0.0 B)

This can be seen ip is 172.17.0.2, and our host instance ip is 10.0.0.83. So, if a simple example of using the host ip: 5000, is a not visit this page. Here we need to do port mapping, for example:

docker run -p 80:5000 training/webapp

Container and can start more, use a different port mapping, for example:

docker run -p 8000:5000 training/webapp

This allows us to deploy two web server, listening on port 8000 external ports are already examples of port 80.

4. Volume Mapping

Docker internal container has its own file system, the file system is isolated from the outside. We can also roll in the docker container external volume mapping. So that after the destruction of container, where volume data is still stored locally. MongoDB online course from industrial experts.
E.g: docker run –v /opt/datadir/:/var/lib/mysql mysql

#mongodb course #mongodb training #mongodb online course #best mongodb course #mongodb full course #learn mongodb online

1.25 GEEK