Source From Here
Docker has quite an amount of buzz around it today because it makes so many things easy that were difficult with virtual machines.
Docker containers makes it easy for Developers, Systems Administrators, Architects, Consultants and others to quickly test a piece of software in a container;much quicker than a virtual machine, and using less resources. The average command in Docker takes under a second to complete.
SIMPLE USE CASES
COMPLEX USE CASES
Docker containers run a single process when started, but complex installations of software which require multiple daemons running simultaneously (RHEV-M, Satellite, etc) can be done. However, they require more engineering work using either Bash scripting or something like: Using Supervisor with Docker or SystemD.
PRODUCTION VS. DEVELOPMENT
At the time of this writing Docker has not yet reached version 1.0 and Red Hat Enterprise Linux 7 has not yet been released as generally available, so production workloads are not recommended. Also, take note that some of the examples in this tutorial make use of docker to test software from different versions of CentOS and Red Hat Enterprise Linux; while this will have limited support, it is quite useful for quick testing and reading man pages.
CENTOS AND RED HAT ENTERPRISE LINUX
This tutorial will focus on integration with Red Hat technologies including CentOS and Red Hat Enterprise Linux. As mentioned, at the time of this writing, Docker has not yet reached version 1.0 and Red Hat Enterprise Linux 7 has not yet been released as generally available, so the majority of the hands on portion of this tutorial will use CentOS. Many of these tutorials can also be completed using Fedora.
One of the key advantages of using Docker is it’s centralized image management server, called a Registry Server. The Docker project maintains a public registry server which hosts images they maintain, as well as images created by the community. This registry service is free to use, as long as the images are public. As one builds images, they are made up of layers. These layers are shared together in, what is called a repository. Users on the registry can share multiple repositories.
Docker has an official CentOS 6 repository which they support: https://index.docker.io/_/centos/
This tutorial will use several public CentOS repositories which I have created and shared on Docker’s public registry. I have created a separate repository for each major version of CentOS: https://index.docker.io/u/fatherlinux/
OS VIRTUALIZATION VS. APPLICATION VIRTUALIZATION
Why separate repositories for each major version of Red Hat Enterprise Linux or CentOS? This was a conscious decision because we are working with a full enterprise Linux distribution versus a single application. Historically, it has been best practice to install a fresh copy when upgrading major versions of Red Hat Enterprise Linux or CentOS. While it is possible to upgrade in place and share multiple versions in a single repository, this is not the preferred method with an enterprise operating system.
However, when virtualizing individual applications, it may be very appropriate to upgrade in place and share all versions within a single repository (See section: Set Up a Registry Server).
After reading this tutorial, you may be excited to set up your own registry server. This is easy to do, but has some caveats, so think think through whether it is worth just using a hosted registry server.
Now we will run through some basic operations to get you up and running.
In CentOS 6, this requires the user space tools from the EPEL. Personally, I prefer to disable after installation so that later, full system updates don’t break the system.
From CentOS7, the Docker installation become simple (ref):
This will automatically pull the latest CentOS 4 image from the remote repository and cache it locally.
Pull an Image
This will pull the latest CentOS 5 image from the remote repository and cache it in the local index. If the image you are pulling is made up of layers, all of the layers will be pulled.
This will list all of the images in the local index and display how they are linked to each other. Every time a new container is spawned from an image, it will create another copy on write image to save it’s changes too. The tree structure will help make things clear.
Tag an Image
It makes it easier to deal with images if they are tagged with simple names
Run a Container
Notice how easy it is to test a command in CentOS 4
Log in to the Hosted Docker Registry
To create repositories on the public Docker Registry, it is necessary to sign up at: https://www.docker.io/account/signup/
Once you have created an account, you will need to login from the command line:
Dockerfile: Commit an Image
Once logged in to the public Docker Registry, new images can be built and committed with code using a Dockerfile. This allows an administrator to automatically rebuild a known good starting point quickly and easily. It is recommended to always start with an image defined by a Dockerfile.
There are a couple of important things to notice with this Dockerfile. First, the FROM directive specifies a username and repository: fatherlinux/centos6-base. This will pull the latest image from the centos6-base repostiory. In this example, I have provided the source repository for you. Second, the only change we have specified in the Dockerfile, is to update CentOS to latest available packages.
BUILD AND TAG THE IMAGE
INSPECT THE NEW IMAGE
This will list all of the layers in an image:
Notice that the new image is now available for deployment.
TEST THE NEW IMAGE
Manually: Commit an Image
Once a container has changes made locally, they can be committed to the local index. This allows you to check point and continue. It also allows you to create new images based off of this modified container.
MODIFY THE IMAGE
Make some changes inside the container. In this example, change the hostname and exit
COMMIT THE CONTAINER
First, get a list of containers. Notice that every container has a CONTAINTER ID and a STATUS. A status of Up means the container is currently running, while a status of Exit indicates that the container has been stopped. Think of the CONTAINER ID as a branch from the base image that contains all of the changes that were made to the container while it was running. By default this data is saved even after the container is shut down.
Now, commit the container back as a branch of it’s base image
Tag the new image with something meaningful
Push a Container
Once a container is committed locally, it can be pushed back to the registry server to be shared. The changes will be pushed as a layered image. Notice how quickly it is able to push only the differences between your modified image and the base image. This is a big part of the value.
Pull All Standard Images
These CentOS images are in the public Docker repository.
Create Base Image
This method was developed with guidance from this script. This example is based on CentOS 6.
Create a tar file of the system
Copy the tar file to where the consuming system and Import the image
Remove Old Docker Containers
By default, Docker keeps changes for every container which is instantiated. When testing, this can be undesirable. Be careful because this will remove all branches/data. Any containers which have not been committed will have all data deleted:
* Docker Document - Installing Docker - CentOS-7
- [ 英文學習 ] (7)
- [ 計算機概論 ] (1)
- [ 深入雲計算 ] (8)
- [ 雜七雜八 ] (5)
- [ Algorithm in Java ] (26)
- [ Data Structures with Java ] (82)
- [ IR Class ] (19)
- [ Java 文章收集 ] (21)
- [ Java 代碼範本 ] (42)
- [ Java 套件 ] (11)
- [ JVM 應用 ] (7)
- [ LFD Note ] (2)
- [ MangoDB ] (7)
- [ Math CC ] (3)
- [ MongoDB ] (8)
- [ MySQL 小學堂 ] (1)
- [ Python 考題 ] (2)
- [ Python 常見問題 ] (13)
- [ Python 範例代碼 ] (7)
- [心得扎記] (1)
- [網路教學] (3)
- [C 常見考題] (2)
- [C 範例代碼] (4)
- [C/C++ 範例代碼] (18)
- [Intro Alg] (4)
- [Java 代碼範本] (25)
- [Java 套件] (15)
- [Linux 命令] (60)
- [Linux 小技巧] (34)
- [Linux 小學堂] (32)
- [ML In Action] (14)
- [ML] (44)
- [MLP] (7)
- [Python 學習筆記] (1)
- [Quick Python] (20)
- [Software Engineering] (8)
- [The python tutorial] (7)
- 工具收集 (21)
- 設計模式 (18)
- 資料結構 (68)
- ActiveMQ In Action (13)
- AI (6)
- Algorithm (4)
- Android (11)
- Big Data 研究 (15)
- C/C++ (68)
- C++ (19)
- CCDH (20)
- Coursera (2)
- Database (1)
- Design Pattern (1)
- Device Driver Programming (42)
- Docker (31)
- Docker 工具 (1)
- Docker Practice (6)
- Eclipse (1)
- English Writing (52)
- ExtJS 3.x (4)
- FP (1)
- FreeBSD (1)
- GCC (2)
- Git (4)
- Git Pro (4)
- GNU (30)
- Groovy (81)
- Hadoop (65)
- Hadoop. Hadoop Ecosystem (1)
- Java (258)
- Java Framework (1)
- Java UI (3)
- JavaIDE (2)
- JFreeChart (2)
- Kali/Metasploit (6)
- KVM (1)
- Learn Spark (10)
- Linux (238)
- Lucene (19)
- Math (8)
- MPI (3)
- Nachos (4)
- Network (3)
- NLP (1)
- OO (28)
- OpenCL (1)
- OpenMP (3)
- OSC (1)
- OSGi (10)
- Perl (24)
- Python (187)
- Python Std Library (36)
- Python tools (4)
- QEMU (1)
- R (1)
- RIA (14)
- RTC (5)
- Ruby (68)
- Ruby Packages (8)
- Scala (75)
- ScalaIA (15)
- TensorFlow (1)
- Tools (11)
- UML (2)
- Unix (18)
- Verilog (3)
- Vmware (2)
- Windows 技巧 (10)
- ► 2016 (273)
- [ 文章收集 ] Docker 實作入門
- [ 常見問題 ] How to get the input file name in the map...
- [ In Action ] Ch10. Pig: Speaking Pig Latin (3)
- [ In Action ] Ch10. Pig: Using Pig (2)
- [ In Action ] Ch10. Pig: In the beginning (1)
- [Linux 常見問題] How do I change my Vim highlight line...
- [ 文章收集 ] A Practical Introduction to Docker Contai...
- [Linux 文章收集] CentOS : Manual IP network configurat...
- [Linux 文章收集] How to configure static DNS on CentOS...
- [Linux 常見問題] Pseudo-terminal will not be allocated...
- [Linux 文章收集] 卸載 (unmount)/退出檔案系統
- [ Java 常見問題 ] How to encode URL to avoid special c...
- [Linux 常見問題] ssh_exchange_identification: Connecti...
- [Linux 常見問題] How to check how long a process has b...
- [Linux 文章收集] How process input and output works in...
- [ Python 文章收集 ] Python Decorators II: Decorator Ar...
- [ Python 文章收集 ] Understanding Python Decorators in...
- [Linux 文章收集] Linux Set Date and Time From a Comman...
- [ RTC Client Lib ] SC - Download build result log ...
- [Linux 文章收集] sshpass Command : Non-interactive Pas...
- [ 常見問題 ] Named parameters for Closure/Method
- [ RTC Client Lib ] SC - Retrieve change set based ...
- [ Java 常見問題 ] JSch - Sending commands to server vi...
- [Linux 常見問題] 複製虛擬機Linux，網卡啟動失敗 Device eth0 does no...
- [ Java 常見問題 ] Get an OutputStream into a String
- [ RTC Client Lib ] SC - How to get ChangeSet(All f...
- [ Python 文章收集 ] Decorators I: Introduction to Pyth...
- ▼ 四月 (27)
- ► 2014 (245)
- ► 2013 (112)
- ► 2012 (197)
- ► 2011 (265)