Home > other >  Recommend a translation: "how to play the Dcoker: Hello World, the development environment and
Recommend a translation: "how to play the Dcoker: Hello World, the development environment and

Time:09-27

Address: http://wiki.jikexueyuan.com/project/wiki-journal-201507-1/docker.html

Play Dcoker: Hello World, the development environment and the application of you

The article translation: zhou times with
Time: July 13, 2015,
The original author: Tugberk Ugurlu
Article categories: cloud computing and security

About this article
Docker container is an open source application engine, allows developers to pack their applications and rely on the package to a portable container, and then release to any popular Linux machine, almost no performance overhead, can easily run in the machine and data center, one of the most important is that they do not depend on any language, including system framework,

The article content
When you want to write blog record or something, most likely you have learned something:) just like I am now, I have to study Linux for some time, I didn't expect to like this goes well, it feels wonderful, I have to admit before Windows have been used as a development environment let I missed some really good stuff, however, there is one thing that makes me feel very regret: the.net ecosystem, for writing applications, this is one of the very powerful ecological system, and can be easily transplanted to the Windows environment, the development of the environment I the door was open,

I have already started Docker for some time, most of the time I have been trying to understand the concepts, because if the long-term use of Windows for development, these concepts will be very strange for you, after understanding the concepts, the most interesting part is coming, in this article, I'll show you why I so love Dcoker,

Why did you choose Dcoker

Here is why I think Docker useful (compared with others why there is no much different) :

Repeatable, declarative environment, in your development, CI, QA (also known as your Pre - Production) environment using the Docker compose will become more convenient and quick,

When you use Redis in learning, new tools, such as the RabbitMQ reading documents and try to absorb them, perform Dcoker running commands, create a container, use the tool of development in the container, finally delete container,

Can help you allocate file, AWS, Azure, or whatever, wherever you are, you can use the same script to allocate file,

Will change the way you think, your solution modular (here I mentioned microservices), which can help you avoid some wrong choices, for example, through the stack to each part of the development and application, it not only can help you better understand the program, use the right tools for development, and you also can give you a different part of the solution to specialize in different areas of technology developers to develop respectively, I am in this is highly recommended to look at. The.net Rocks of podcast Building microservices with Howard Dierking to deeper understanding of this part of the

That I'm not sure, but the Docker makes people Docker warehouse environment becomes not so important,
May also have a lot of other elements in Docker let me fall in love with it,

Hello World

I guess you have now installed Docker is preparing to come with me to learn it, next, I'll use the Ubuntu 14.04 LTS, should be the same on OS X,

As you might expect, "Hello World" this case is also been statement and packaging (as noted earlier, the docker), in order to let the "Hello World" to run, only need to perform the following command:

Docker run ubuntu: 14.04/bin/echo "Hello world"
When you execute this code execution process in Docker Hello World docs in brief to explain, if you have an image based on Ubuntu 14.04 container, inside output 'Hello World' then exits,



As mentioned above, after completion of the container in the output will disappear, but is still running, if you execute the following code, you will find that container,

Docker ps - a


By running based on the obtained from docker ps output to the orders of the container ID, we can open the corresponding container,

Docker start - attach 6 a174ac370a2
We also use, attach the switch before connecting to STDOUT/STDERR and signals, which is why we can see the hello world write in our console, let's look at a more practical example of container related,

Docker run ubuntu - d: 14.04/bin/sh -c "while true; Do the echo hello world; Sleep 1; The done
"This is what you can in the Docker Hello World doc of "A daemonized Hello World" example of section, it is interesting to note the -d switch, it tells the Docker run container and put it in the background, if we now run Docker ps, we can see the container is still in the running state,



Perform the following based on container ID code, we can connect to a running container of STDOUT/STDERR,

Docker attach ff2847155ced


You can separate from the container, through the CTRL - p CTRL - q let it run separately,

Again, you should have noticed for the first time we run the command of execution spent a short period of time to complete, because you need to download all the images from the registry, but the second is almost finished in a flash is executed, for Ubuntu 14.04 already exists, so, we recognize the Docker images are immutable, but a combination of, this is great, by performing a Docker images command you can see under your host images,



Development environment

Mentioned earlier, the introduction of the Docker can easily file and use them, for example, Redis is on Docker registry, I will run it as another container,

Docker run - name my - redis - d redis: 3.0.2






We can see the TCP port 6379 is out of the show, that's what Redis display port, however, I need to know the host's IP address to connect to Redis instance, we can inspect the command to get a running the IP address of the container,

Docker inspect - format '{{. NetworkSettings. IPAddress}}' dfaf0cf33467


Now I can use my installed redis - in my host cli tool to connect to redis instance,

Redis - 172.17.0.10 cli - h - p 6379


I can choose to open or the end of the container operation, almost all of the things that can follow such a process (such as Ruby, GoLang, Elasticsearch, directing, RabbitMQ, you - the name - your - thing and so on), for example, in Python development environment, you can perform the following docker run the command:

Docker run - t - I python: 2.7.10/bin/bash
This can give you to create a Python interactive container, you can use it to do anything you want to do:



When you finish, you can use the exit command to end in a container or input Ctrl - D interactive process, effectively stop the container, the container is still very easy to use, by running the docker ps - a and the ID of the running start commmand to container to obtain its ID, then you can start the container again,

You might be curious like Redis, directing and Elasticsearch such tools is how to integrate into the world, because they need to save Data to disk but Docker containers are created don't have the concerns, this is a very worth thinking problem, with Data Volumes, Docker can be a very good solution to this problem,

your application
The above process was very good, but our application to how to build? If you use the Docker, there will be many different ways, but let me tell you one of the most simple and most efficient method, which may give you a little inspiration,

Take an example for application, I choose will be based on the Node. Js Octopus Deploy Library Web application docker, we need to achieve by Dockerfile, Dockerfile is a well-written document, here's the Octopus Deploy in the Library how to apply Dockerfile:

FROM the node: 0.12.7

RUN [" NPM ", "install", "gulp", "- g"]
RUN [" NPM ", "install", "bower," "-g"]
RUN [" NPM ", "install", "grunt - cli", "- g"]

COPY the/app
WORKDIR/app

RUN [NPM ", "" install"]
The RUN [" bower, "" - allow - the root", "install"]

EXPOSE 4000

ENTRYPOINT [" gulp "]
Self description is, in my opinion, the best part of this document, we define the application image based on node: 0.12.7 image, including node. Js file, and then, we need to run a few NPM command to install the things we need, then we copy files change work path, finally, set up the dependencies, open the TCP port 4000, clear entry point command,

When you run a gulp of the default task, Octopus Deploy to begin to work and start the server, which is why this is our entry point,
Now we can start to build our application image:

Docker build - t octopus - library.


If all made good progress, application of structures, and the creation of the image, in the end, we can use the same run a command to start the container and let it run under our host:

Docker run - t - d - 4040 p: 4000 octopus - library
nullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related