Docker on CentOS for beginners

来源:http://www.cnblogs.com/steven-yang/archive/2016/09/02/5835956.html
-Advertisement-
Play Games

[comment]: Docker on CentOS for beginners Introduction The article will introduce Docker on CentOS. Key concepts Docker Docker is the world's leading ...


Introduction

The article will introduce Docker on CentOS.

Key concepts

Docker

Docker is the world's leading software containerization platform.
Docker is using union file systems which is a layered file system.
When docker run a container, every image consists of a serials of read-only layers,
and the container provides a read-write layer, and Docker combines these layers into one image,
and forms a single coherent file system on the host OS.

Q: What is the relationship between the docker host OS and the container base image OS?
A: The container's kernel is going to be the one from ubuntu, but nothing more.

Docker for Windows and Docker for Mac

Docker only support applications on Linux.
Docker cannot run on Windows and Mac directly. Docker will create a VM via Virtual Box, and run command in the VM.

Docker engine

Docker engine is a light weight Docker, is used to create Docker images and run Docker containers.

Docker daemon and Docker client

Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers.

Docker registries

Docker has a good ecological environment, there are some registries that store images and other materials on the Internet.

Docker Hub is a public registry and stores images.

images

An image is a file and is a read-only template, Docker can use it to create containers.
Docker images can be built from 2 ways.

  • Build it from Dockfile
  • Build it from a container.

containers

Docker containers are similar to a directory. A Docker container holds everything that is needed for an application to run. Each container is created from a Docker image. Docker containers can be run, started, stopped, moved, and deleted. Each container is an isolated and secure application platform. Docker containers are the run component of Docker.

Dockerfile

Dockerfile files can be used to create images by Docker.
Dockerfiles are files whose names are 'Dockerfile'. A Dockerfile is a scripts to create an image.
In general, a Docker file is based on another image. For example: a image inheritance chain is:

spark : hadoop : centos : scratch.

Base images like 'centos' are images that are from the scratch image which is an explicitly empty image from the official Docker.
We can consider 'scratch' is a reversed word by Docker. (You cannot pull, push an image named as 'scratch'.)

In fact, base images are not always OS images. like hello-world image, its Dockerfile is

FROM scratch
COPY hello /
CMD ["/hello"]

Why Docker is better than VMs

  • Performance
    It is said that the performance of running applications in Docker is same as running them on native machine.
    Meanwhile, VMs performance is slower twice times than native machines.

Installation & configuration the Docker repository file

Method 1: Run the Docker installation scripts

curl -fsSL https://get.docker.com/ | sh

Method 2: From scripts

  • Install Docker

    $ sudo yum install docker

    or light weight docker

    $ sudo yum install docker-engine
  • Create Docker repository file
    The configuration can help Docker to pull images from a registry.

    sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
    [dockerrepo]
    name=Docker Repository
    baseurl=https://yum.dockerproject.org/repo/main/centos/7/
    enabled=1
    gpgcheck=1
    gpgkey=https://yum.dockerproject.org/gpg
    EOF

Configuration Docker service

# configure load the Docker service at boot
sudo chkconfig docker on
# start Docker
sudo service docker start
# create a Docker group
sudo groupadd docker
# alow non-root user to run Docker
sudo usermod -aG docker $(whoami)

Verify Docker is installed

docker run hello-world
docker version
docker info

Docker key commands

Docker help

docker --help
docker [command] --help

Search an image

You may go to Docker Hub, search an image you want to use.
or

# search images related to 'spark'
docker search spark

Output;

INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/sequenceiq/spark An easy way to try Spark 287 [OK]
docker.io docker.io/gettyimages/spark A debian:jessie based Spark container 27 [OK]
docker.io docker.io/singularities/spark An Apache Spark development Docker image 12 [OK]
docker.io docker.io/shopkeep/spark Docker container with Spark, Scala, SBT, a... 7 [OK]

Pull an image

# pull the image named 'sequenceiq/spark'
docker pull sequenceiq/spark

List local images

docker images

Output:

REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hello-world latest c54a2cc56cbb 8 weeks ago 1.848 kB
docker.io/shopkeep/spark latest 4be7b9be182e 12 months ago 1.693 GB

Create a container

# create a container from image name
docker create -t -i shopkeep/spark

# Or create a container from image id
docker create -t -i c54

Output:

5bb2d0aaa227154920733fb9f13e1571fe40254dd1b3373b617550cdde71e57e

List local containers

# Show all containers
docker ps -a

Output:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5bb2d0aaa227 shopkeep/spark "/bin/bash" 15 minutes ago Created insane_kowalevski

# Show running containers
sudo docker ps

Run a container

docker start -a -i 5bb

Output:

root@5bb2d0aaa227:/opt/spark#

Note: Docker is smart enough to match partial container id 5bb with the container id 5bb2d0aaa227...

Enter a running container with the existing TTY

# in most cases, the running container was started with a command 'docker start 5bb'
docker attach 5bb

Enter a running container with new TTY

docker exec -ti 5bb bash

Exit from a running container

root@5bb2d0aaa227:/opt/spark# exit

NOTE: the exit command from the last TTY will stop the container.

Stop a container

docker stop 5bb

Save a container as an image

docker commit 5bb my/image1

Output:

sha256:5cf350490e9e8b7495acb753f4041e34788e4881300b28ffc958db06d45fb4b3

Save an image to a tar archive

docker save my/image1 > ~/my_image1.tar

Load an image from a tar archive

docker load -i ~/my_image1.tar

Docker images/containers locations

  • /var/lib/docker
  • C:\Users[user name].docker

References


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 目錄: hdfs 命令操作本地 hbase Azure HDInsight HBase表數據導入本地 hbase hdfs命令操作本地hbase: 參見 HDP2.4安裝(五):集群及組件安裝 , 創建本地 hbase集群後,使用hadoop hdfs 命令在訪問 hbase 存儲數據時,數據在hd ...
  • hdfs dfs -cat URI : 查看文件內容 -ls <args>: 查文件列表 -mkdir <paths> : 創建目錄 The behavior is much like unix mkdir -p creating parent directories along the path ...
  • 在命令行下mysql的數據導出有個很好用命令mysqldump,它的參數有一大把,可以這樣查看: mysqldump 最常用的: mysqldump -uroot -pmysql databasefoo table1 table2 > foo.sql 這樣就可以將資料庫databasefoo的表ta ...
  • 今天簡單分享一下StackExchange.Redis客戶端中配置主從分離以及哨兵的配置。 關於哨兵如果有不瞭解的朋友,可以看我之前的一篇分享,當然主從複製文章也可以找到。http://www.cnblogs.com/tdws/tag/NoSql/ 為什麼要有這篇分享呢,是因為我之前也有一些疑問,相 ...
  • 今天遇到一個很有意思的問題,一個開發人員反饋在測試伺服器ORACLE資料庫執行的一條簡單SQL語句非常緩慢,他寫的一個SQL沒有返回任何數據,但是耗費了幾分鐘的時間。讓我檢查分析一下原因,分析解決過後,發現事情的真相有點讓人哭笑不得,但是也是非常有意思的。我們先簡單構造一下類似的案例,當然只是簡單模... ...
  • MySQL 賦予用戶許可權命令的簡單格式可概括為: 1 grant 許可權 on 資料庫對象 to 用戶 一、grant 普通數據用戶,查詢、插入、更新、刪除 資料庫中所有表數據的權利 1 grant select on testdb.* to common_user@'%' 2 grant inser ...
  • Oracle使用正則表達式離不開這4個函數: 1。regexp_like 2。regexp_substr 3。regexp_instr 4。regexp_replace 看函數名稱大概就能猜到有什麼用了。 regexp_like 只能用於條件表達式,和 like 類似,但是使用的正則表達式進行匹配, ...
  • 目錄與路徑 cd:切換目錄 例如:cd ~willhua,則回到用戶willhua的主文件夾 cd ~或者cd,則表示回到自己的的主文件夾 cd -,則表示回到上個目錄 pwd:顯示目前所在目錄 參數: -p,顯示當前路徑,而非使用連接路徑 mkdir:新建新目錄 參數: -m:直接配置文件的許可權, ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...