一、Docker简介
Docker主机(Host):安装了Docker程序的机器(Docker直接安装在操作系统之上);
Docker客户端(Client):连接Docker主机进行操作;
Docker仓库(Register):用来保存打包各种打包好了软件镜像;
Docker镜像(images):软件打包好的镜像;放在Docker仓库中。
Docker容器(Container):镜像启动后的实例称为一个容器,容器是独立运行的一个或一组应用。
使用Docker的步骤:
1、安装Docker仓库
2、去Docker仓库找到这个软件对应的镜像
3、使用Docker运行这个镜像,这个镜像就会生成一个Docker容器
4、对容器的启动停止就是对软件的启动停止
二、安装Docker
安装命令如下:
安装命令如下:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
也可以使用国内 daocloud 一键安装命令:
curl -sSL https://get.daocloud.io/docker | sh
直到出现Complete
!
三、Docker的启动和停止
启动Docker命令systemctl start docker
查看版本号:docker -v
root@iZwz92jchyefq3joc3wv9eZ:~# docker -v
Docker version 20.10.7, build f0df350
下次开机自启动systemctl enable docker
root@iZwz92jchyefq3joc3wv9eZ:~# systemctl enable docker
Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable docker
停止dockersystemctl stop docker
root@iZwz92jchyefq3joc3wv9eZ:~# systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:
docker.socket
四、安装nginx
1.拉取最新版镜像
docker pull nginx:latest
2.查看本地镜像
docker images
3.运行容器
docker run --name nginx-test -p 80:80 -d nginx
提示:
-name nginx-test:容器名称。
-p 80:80: 端口进行映射,将本地 80 端口映射到容器内部的 80 端口。
-d nginx: 设置容器在在后台一直运行
4.查看容器列表
docker container ls
5.启动容器
docker start nginx-test
6.验证