1.1 CentOS安装Docker容器

Dockers简介

软件开发中最为麻烦的事情可能就是配置环境了。由于用户使用的操作系统具有多样性,即便是使用跨平台的开发语言都不能保证代码能够在各种平台下都可以正常运转,而且可能在不同的环境下我们的软件需要依赖的其他软件包也是不一样的。

Docker属于对Linux容器技术的一种封装(利用了Linux的namespace和cgroup技术),它提供了简单易用的容器使用接口,是目前最为流行的Linux容器解决方案。Docker将应用程序与该应用程序的依赖打包在一个文件里面,运行这个文件,就会生成一个虚拟容器。程序在这个虚拟容器里面运行,就好像在真实的物理机上运行一样。有了Docker就再也不用担心环境问题了。

目前,Docker主要用于以下几个方面:
1、提供一次性的环境。
2、提供弹性的云服务(利用Docker很容易的实现扩容和收缩)。
3、实践微服务架构(隔离真是环境在容器中运行多个服务)。

安装Docker

0、确定操作系统内核版本(CentOS 7要求为64位,内核版本3.10+;CentOS 6要求64位,内核版本2.6+)

[root@localhost ~]# uname -r
3.10.0-1062.4.1.el7.x86_64

1、在CentOS下使用yum安装Docker并启动

[root@localhost ~]# yum -y install docker-io
[root@localhost ~]# systemctl start docker

2、查看Docker的信息和版本

[root@localhost ~]# docker version
[root@localhost ~]# docker info

3、运行Hello-World项目来测试Docker。第一次运行时由于本地没有hello-world的镜像,因此需要联网进行下载。

[root@localhost ~]# docker run hello-world

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.
    (amd64)
 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://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

4、关于镜像文件的下载运行查看以及删除等。

1)下载镜像

[root@localhost ~]# docker pull <name>

2)运行镜像

[root@localhost ~]# docker run <name>
[root@localhost ~]# docker run -p <port1>:<port> <name>

3)查看镜像文件

[root@localhost ~]# docker image ls
[root@localhost ~]# docker image

4)删除镜像文件——首先要停止所有的container,如果不停止就会报错

[root@localhost ~]# docker stop $(docker ps -a -q)

如果提示镜像被container加载着,继续使用如下命令

[root@localhost ~]# docker rm $(docker ps -a -q)

然后使用以下命令即可

[root@localhost ~]# docker rmi <name>

5、容器的查看以及停止

1)查看正在运行的容器

[root@localhost ~]# docker ps

2)停止运行的容器

[root@localhost ~]# docker stop <container-id>
[root@localhost ~]# docker stop <name>

3)对于那些不会自动终止的容器,就可以用下面的方式来停止

[root@localhost ~]# docker container kill <container-id>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值