
Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源。 Docker
可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。
容器是完全使用沙箱机制,相互之间不会有任何接口,更重要的是容器性能开销极低。
Docker能干什么?

镜像:一个只读的模板,可以通过这个模板创建容器服务,一个镜像可以创建多个容器(最终服务运行或者项目运行就是在容器中)
容器:
仓库:集中存放镜像文件的场所。Docker用Registry来保存用户构建的镜像。Registry分为公有和私有两种卸载之前的Dokcer:
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
安装Docker软件包:
yum install -y yum-utils
使用阿里云镜像:
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装DockerEngine和容器:
yum makecache fast
yum install docker-ce docker-ce-cli containerd.io
启动Docker:
systemctl start docker
docker version#查看版本
配置aliyun镜像(在/etc/docker下新建daemon.json文件):
vi daemon.json
#添加以下内容
{
"registry-mirrors": ["https://z117ufx7.mirror.aliyuncs.com"]
}
查看镜像:
docker images
拉取hello-world镜像:
docker pull hello-world
再次查看镜像:
docker images
#输入命令后应该有如下内容
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 9 months ago 13.3kB
运行hello-world镜像:
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/
查看容器:
#因为hello-world镜像运行后会停止,所以需要-a参数才能查看所有的镜像
docker ps -a
#执行命令后应该有如下内容
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9df5d2e8d1fd hello-world "/hello" About a minute ago Exited (0) About a minute ago condescending_cray
删除容器和镜像:
#删除容器
docker rm 9df5d2e8d1fd(此次填写docker ps -a查询到的CONTAINER ID的值)
#删除镜像
docker rmi hello-world:latest