MENU

CentOS安装使用Docker

April 18, 2017 • Security

UnEfeqF.jpg

环境要求

Docker要求系统必须在CentOS 6以上,内核版本必须是2.6.32-431以上查看CentOS版本:

cat /etc/issue
lsb_release -a
cat /etc/redhat-release
rpm -q centos-release

# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

查看内核版本:

uname -r
# uname -r
3.10.0-514.10.2.el7.x86_64

安装Docker

CentOS6可以使用 EPEL 库安装 Docker,命令如下:

sudo yum install http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm
sudo yum install docker-io

CentOS7 系统 CentOS-Extras 库中已带 Docker,可以直接安装:

sudo yum install docker

运行命令更新下现有库:

yum updatesudo yum install docker-io

安装之后启动 Docker 服务,并让它随系统启动自动加载:

sudo service docker start
sudo chkconfig docker on

测试Docker安装是否成功,使用 hello world :

docker run hello-world

Unable to find image 'hello-world:latest' locally
Trying to pull repository docker.io/library/hello-world ... 
latest: Pulling from docker.io/library/hello-world
78445dd45222: Pull complete 
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

命令速查

查看 Docker 的守护进程

service docker start

Docker 系统启动时运行

chkconfig docker on

登录 https://hub.docker.com/

docker login

查找官方仓库中的镜像

docker search

创建镜像

docker pull [ubuntu]

运行容器

docker run
    -t -i
    -d      //后台运行

启动已终止容器

docker start
    -i

终止容器

docker stop

终止并重启

docker restart

进入容器

docker attach

列出容器

docker ps
    -a

查看容器输出信息

docker log

列出本地镜像

docker images

提交更新

docker commit

    -m "" -a "作者"

修改镜像的标签

docker tag

创建新镜像 Dockerfile

docker buila

上传到仓库

docker push

导出镜像

docker save

裁入镜像

docker load

移除本地镜像

docker rmi

移除容器

docker rm

导出某个容器

docker export

导出某个容器

docker import

查看 当前运行的 images

> docker images

查看 当前运行的 container, -a 所有的 container 默认只显示运行中, -q 返回 id

> docker ps -a -q

删除 images 或 container

> docker rmi #删除 images
> docker rm #删除 container

将 container(id) 提交到 image(name)

> docker commit id name

docker 上传

> docker tag id docker.io/{username}/{images_name}
> docker push docker.io/{username}/{images_name}

有时候不加 docker.io 会有问题.

Tags: docker, CentOS
Archives QR Code
QR Code for this page
Tipping QR Code