Docker on CentOS for beginners
[comment]: # Docker on CentOS for beginners
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
- Docker website
- Docker Overview
- Docker installation
- How is Docker different from a normal virtual machine?
- What is the relationship between the docker host OS and the container base image OS?
Docker on CentOS for beginners的更多相关文章
- Docker安装CentOS
系统环境: 腾讯云公共镜像 CoreOS 7.1 X64 #docker 下载centos镜像docker pull centos #下载centos所有的镜像docker pull ...
- 关于Docker官方CentOS镜像无法启动mysqld的总结
很多童鞋反映,在Docker官方CentOS镜像中安装了Mysql server后,无法正常启动. 无法正常启动表现为两种情况: 1> 初始完数据库后,mysqld启动报错 2> syst ...
- docker on centos
docker最好在centos7上安装,centos6.5上似乎麻烦不少 这里直接在centos7上安装,要提前装一下epel的repo yum install docker 安装就行 chkconf ...
- docker~在centos容器中安装新程序
上一篇我们使用了阿里加速器安装了centos镜像,然后创建了一个新容器,运行了这个镜像,这一讲我们来为这个镜像添加一些应用程序,然后再保存容器,push容器到仓储,大家就可以直接pull我生产的容器了 ...
- 使用docker搭建centos虚拟机
网上有很多安装linux的,这里不记录; windows安装docker 转自:https://www.cnblogs.com/samwu/p/10360943.html(windows是家庭版的) ...
- docker安装centos后没有ifconfig命令解决办法
使用docker pull centos命令下载下来的centos镜像是centos7的最小安装包,里面并没有携带ifconfig命令,导致我想查看容器内的ip时不知道该怎么办 yum provide ...
- 使用Docker搭建CentOS 7 + Apache 2.4+ PHP7
从Docker Hub上Pull最新的CentOS 7镜像并新建容器 # sudo docker pull centos docker run -p 8082:80 --name centos_c - ...
- docker打包centos增加中文支持
docker打包centos增加中文支持 前言 使用的某个包的返回值,在本机测试时返回结果是中文,结果打包到docker后返回结果变英文了:猜测是系统语言的问题,进入docker测试了一下,发现果然是 ...
- docker pull centos慢问题的解决方案
1.现象 如果直接docker pull centos 两个小时才down下来8M,很慢 2.解决 [root@localhost network-scripts]# cd /etc/docker [ ...
随机推荐
- shell编程总结
一.学习 shell脚本之前的基础知识 [linux shell中的特殊符号] 1. * :代表零个或多个字符或数字. test后面可以没有任何字符,也可以有多个字符,总之有或没有都能匹配出来. 2. ...
- 利用VBA查找excel中一行某列第一次不为空与最后一列不为空的列数
昨日同事有需求,想知道每个商品第一次销售的月份,以及最后一次销售的月份. 本想通过什么excel函数来解决,但是找了半天也没找到合适的,最后还是通过VBA来解决吧. 使用方法: Excel工具-宏-V ...
- android自定义RadioGroup实现可以添加多种布局
android自带的RadioGroup是继承自LinearLayout,如果布局的时候不是直接写radiobutton,即radiobutton外面还包了一层容器,这时分组是不成功的,因为查找不到r ...
- C# 实现字符串去重
方法一 注:需要.net 3.5框架的支持 string s = "101,102,103,104,105,101,102,103,104,105,106,107,101,108" ...
- Flash Media Server 4.5 序列号 (fms4.5 激活码)
激活码一枚 ,网上找不到的..我今天放出来了哦... 1462-5864-7783-6034-8316-3718 (亲测 可用) 安装前找到系统盘下windows/system32/driv ...
- GET到新技能,SharpCEF,C#和JS的互相调用
winform程序内嵌谷歌浏览器,使用大名鼎鼎的“SharpCEF”.这里科普一下: CEF是什么 CEF是Chromium Embedded Framework的缩写,是个基于Google Chro ...
- 二十一、【.Net开源框架】EFW框架Web前端开发之目录结构和使用FireBug调试方法
回<[开源]EFW框架系列文章索引> EFW框架源代码下载V1.2:http://pan.baidu.com/s/1hcnuA EFW框架实例源代码下载:http://pan.baidu. ...
- MyBatis知多少(20)MyBatis读取操作
上篇展示了如何使用MyBatis执行创建操作表.本章将告诉你如何使用MyBatis来读取表. 我们已经在MySQL下有EMPLOYEE表: CREATE TABLE EMPLOYEE ( id INT ...
- 进阶学习js中的执行上下文
在js中的执行上下文,菜鸟入门基础 这篇文章中我们简单的讲解了js中的上下文,今天我们就更进一步的讲解js中的执行上下文. 1.当遇到变量名和函数名相同的问题. var a = 10; functio ...
- Android之TextView的Span样式源码剖析
Android中的TextView是个显示文字的的UI类,在现实中的需求中,文字有各式各样的样式,TextView本身没有属性去设置实现,我们可以通过Android提供的 Spannab ...