Docker
将程序和程序运行所依赖的所有环境都打包到镜像里。“build once, run anywhere”Docker
是容器的一种实现。
CentOS 下如何安装Docker
:
如下步骤参考菜鸟教程-docker教程。
安装所需的软件包
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
设置仓库
使用以下命令来设置稳定的仓库。
$ sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum-config-manager命令可以进行YUM配置管理。
--add-repo=<软件仓库> | 从指定文件或URL添加(和启用)软件仓库 |
参考:Linux yum-config-manager命令YUM配置管理 - 步留痕 - 博客园
安装 Docker
Dock社区版本免费Engine-Community
$ sudo yum install docker-ce docker-ce-cli containerd.io
启动Docker
$ sudo systemctl start docker
运行HelloWorld
运行 hello-world 映像来验证是否正确安装了 Docker Engine-Community 。
$ sudo docker run 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/
Docker daemon为docker的守护进程。
配置镜像加速器
国内从 DockerHub 拉取镜像有时会遇到困难,此时可以配置镜像加速器
运行 Docker 的云平台选择对应的镜像加速服务。
阿里云镜像获取地址:阿里云登录 - 欢迎登录阿里云,安全稳定的云计算服务平台,登陆后,左侧菜单选中镜像加速器就可以看到你的专属地址了:
sudo systemctl daemon-reload
sudo systemctl restart docker
从镜像创建容器
runoob@runoob:~$ docker run ubuntu:15.10 /bin/echo "Hello world"Hello world
以上命令完整的意思可以解释为
Docker 以 ubuntu15.10 镜像创建一个新容器,然后在容器里执行 bin/echo "Hello world",然后输出结果。
docker run ubuntu:15.10 /bin/echo "Hello world"
Docker 首先从本地主机上查找镜像是否存在,如果不存在,Docker 就会从镜像仓库 Docker Hub 下载公共镜像。这里本地就是不存在。
下载了镜像输出了helloworld