Day 21:docker Getting Started tutorial _ one months

Source: Internet
Author: User
Tags curl docker fedora install node virtual environment docker ps docker run docker registry


A few months ago, Red Hat announced the establishment of a partnership with DotCloud in Docker technology. I didn't have time to learn about Docker, so today, taking advantage of this 30-day challenge, I decided to learn about Docker. This blog post is not about how to use Docker on OpenShift. Read "Technical thinking about OpenShift and Docker" written by Mike McGrath. Also can look at this stackoverflow problem, understand the difference between Docker and OpenShift. What is Docker.

Docker provides an envelope (envelope), or container, that can run your application. It was originally an amateur project launched by DotCloud and was open source in the early days. It attracts a lot of attention and discussion, causing DotCloud to rename it to Docker Inc. It was originally written in the Go language, which is equivalent to a pipeline added to the LXC (LinuX containers,linux container), allowing developers to work on a higher level of concept.

Docker extends the Linux container (Linux containers), or LXC, through a high-level API that provides a lightweight virtual environment for the process alone. Docker leverages LXC, Cgroups, and Linux's own kernel. Unlike traditional virtual machines, a Docker container does not contain a single operating system, but operates on the functionality provided by the operating system in an existing infrastructure. Here is a StackOverflow answer, which describes in very detail all Docker different from pure LXC functional features

Docker will work like a portable container engine. It packages the dependencies of applications and all programs into a single virtual container that can run on any Linux server. This greatly improves the flexibility and portability of programs, whether they need permission, public cloud or private cloud, bare-metal environment, and so on.

The Docker consists of the following:
1. The Docker Server Daemon (daemon), used to manage all containers.
2. Docker command-line client to control the server daemon.
3. Docker mirroring: Find and browse Docker container mirrors. It also visits here to get: https://index.docker.io/Why should I care about these.

Docker is useful because it is often difficult to migrate code from one machine to another. It tries to make the process of software migration more believable and automated. The Docker container can be ported to all operating systems that support running Docker.

See this article for more: How the Fedora Project is embracing Docker but I'm already using virtual machines (VMs)

Until now, the only option to reliably migrate a program is virtual Machines,vms. Virtual machines are now common, but virtual machines are very low-level and provide a complete operating system environment. The problem with a virtual machine is that it's too big to migrate. They contain a lot of information that is not needed, such as hardware drivers, virtual processors, network interfaces, and so on. Virtual machines also require a longer boot time, while also consuming large amounts of memory and CPU resources.

Docker is very lightweight compared to it. It works just like a regular program. This container is not only running fast, it is also very quick to create a mirror and make a file system snapshot. It can be run in a virtual environment like EC2, RackSpace VMs. In fact, a better way to use Docker on MAC and Windows systems is to use vagrant. Docker's original intention was to play a VM-like role, but it started faster and needed less resources. Is it like vagrant?

One of the questions I encountered was whether I should use vagrant or Docker to create a sandbox environment for my next project. The answer is once again the same.

Docker is more of a resource-saving operation than vagrant. The environment provided by Vagrant is actually based on virtual Box. Read StackOverflow's answer to learn more. Oh, no. Another application packaging system

I was puzzled when I first read the Docker packaged application. Why do we need one more application package (packaging system). I've already packaged my Java program as a JAR or a WAR. After spending some time reading about Docker, I understood the meaning of the Docker application package (application package). Docker is a bridge between a virtual machine and your application package like WAR or a JAR. On the one hand, virtual machines are very heavyweight (resource-intensive), because there are unwanted things to be attached to the porting. On the other hand, the application code pack (the application code packages) is very lightweight and does not come with information that is sufficiently reliable to run. Docker a good balance between these two aspects.

In Docker, the application package (application package) means a package that contains the application code and the required deployment environment. For example, in Java we typically package our WEB applications in a WAR file. This WAR file is a very simple package that contains only the code for the application. But applications need a specific deployment environment to run efficiently. Sometimes the deployed environment is different from the development environment. For example, developers use Java 7 development programs, but the environment for deployment is in OpenJDK Java 6, or it is developed on a MAC, but deployed on RHEL. It is also possible that there are systems libraries (system libraries) that have different effects on different applications in both the development environment and the simulation Environment (staging environment). Docker solves this problem by not only packaging the application, but also packaging the application's dependency environment. Start using Docker

Use the instructions in this blog post to install Docker on the Fedora machine

$ vagrant up
$ vagrant ssh

Then install the Docker Fedora Image:

$ sudo docker pull Mattdm/fedora

The above command downloads the Docker Fedora image from the https://index.docker.io/.
After installing the Docker Fedora image, we can use the following command to list all mirrors:

$ sudo docker images

REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
shekhargulati/node_image_007   latest              e12b3054d981        minutes ago      470.3 MB (Virtual 601.8 MB)

Mattdm/fedora                         12.04               8dbd9e392a96        7 months ago        131.5 MB (Virtual 131.5 MB)

The first mirror in the list above is the one I created previously. It is packed with Nodejs and Express fremework. The second mirror is the stored Docker Fedora image.

Now, we run a script within the Docker container:

$ sudo docker run-t-i-p 3000 Mattdm/fedora/bin/bash

After running the above command, we are in the Docker container. We can list all the commands through the LS command.

Now we create the following directory structure/home/shekhar/dev:

$ mkdir-p Home/shekhar/dev
$ cd Home/shekhar/dev

Now, I will install Nodejs. Run the following command to install Node on the Fedora Docker Mirror:

$ sudo yum install NPM

Then we install the Express framework:

$ NPM Install Express-g

After the Express framework is installed, we create a new Express program and then run it:

$ express MyApp
$ cd MyApp
$ npm Install
$ node App.js

The above will start the Nodejs Express program on Port 3000.

Now open another command-line tab, listing all the Docker processes:

$ sudo docker PS
CONTAINER ID        IMAGE                                 COMMAND             CREATED             STATUS              PORTS                     NAMES
4a5715a915e5        Mattdm/fedora   /bin/bash           5 minutes ago up       5 minutes        0.0.0.0:49157->3000/ TCP   Red_duck

You will notice that the 3000 port is bound to the 49157 on this machine. You can test the Express application by using the Curl command shown below:

$ Curl 0.0.0.0:49157
<! DOCTYPE html>

Now commit the mirror and push to the Docker Mirror Registry (registry). Before you do this, you must register a docker registry through https://index.docker.io/account/signup/.

$ sudo docker commit 4a5715a915e5 shekhargulati/node_image_007
$ sudo docker push shekhargulati/node_image_007

Please use your own username and mirror name.

So, my first image has been uploaded to the Docker registry: https://index.docker.io/u/shekhargulati/node_image_007/

You can download this image using the Pull command:

$ Docker Pull shekhargulati/node_image_007

That's what today is all about. Keep feedback.

Original: Day 21:docker--the Missing Tutorial
Translation finishing: Segmentfault

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.