链接:Ubuntu上安装Docker
#启动docker服务:
systemctl start docker
#停止docker服务:
systemctl stop docker
#重启docker服务:
systemctl restart docker
#查看docker服务状态:
systemctl status docker
#设置开机启动docker服务:
systemctl enable docker
查看镜像
docker images
docker images -q#查看所有镜像ID
搜索镜像
docker search redis#查看redis的所有镜像
下载镜像(不指定版本号则下载最新版本)
docker pull redis:5.0#下载Redis镜像,指定版本号为5.0
删除本地镜像
docker rmi 镜像ID#镜像ID从前面的docker images命令获取
docker rmi 'docker images -q'#删除本地所有镜像
宿主机和Nginx容器之间建立了双向映射,对宿主机文件系统的文件修改,等于修改Nginx容器内的文件,反过来,对Nginx容器的文件进行修改等于修改宿主机文件系统的文件.又因为宿主机文件系统内有比较方便的文件修改的软件,因此在宿主机里面进行修改更加便捷,这就是数据卷的意义!
命令 | 说明 |
---|---|
docker volume create 某个数据卷 | 创建数据卷 |
docker volume ls | 查看所有数据卷 |
docker volume rm 某个数据卷名字 | 删除指定数据卷 |
docker volume inspect 某个数据卷名字 | 查看某个数据卷的详情 |
docker volume prune 某个数据卷名字 | 清除数据卷 |
root@ubuntu:/home/ubuntu# docker run -d --name nginx -p 80:80 -v html:/usr/share/nginx/html nginx
476e65fadf296b7f16ddd41de7ec853115f3d11be5176bf7904eddeac9b257db
//宿主机内的html目录映射到/usr/share/nginx/html,
//宿主机的目录默认是/var/lib/docker/volumes/下面的,
//这里直接html:/usr/share/nginx/html其实
//相当于/var/lib/docker/volumes/html映射到:/usr/share/nginx/html
root@ubuntu:/home/ubuntu# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
476e65fadf29 nginx "/docker-entrypoint.…" 4 seconds ago Up 3 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp nginx
8cb1b0be2e14 mysql "docker-entrypoint.s…" 6 hours ago Up 6 hours 33060/tcp, 0.0.0.0:3307->3306/tcp, :::3307->3306/tcp mysql2
e325751d7107 mysql "docker-entrypoint.s…" 7 hours ago Up 7 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
root@ubuntu:/home/ubuntu# docker volume ls
DRIVER VOLUME NAME
local 1aeb968aa95ac9884b620f266d8b45da10beb5413dac4d540a62a723e05d4902
local 2c66b24d7f2453b978a730b8d8de3e97b501dd78ab2387a6944f948f29436896
local 4ff1c5f9a98ce72505d2a35d53304d1b8f628fe4d234bb3addbdca4b7cd2b08e
local 5f0f95ce74a82ae7f3b222da0383540e5a080d97bc4e7c2806b2bf1de92a35ae
local 5f277e59d9025a02d2728ce182d144a8d5ce2e6730569198c32d375992fb2620
local 8b2a53b2ddfa3a0929853208e6333a585bcf2373ae6e3f850016106c5874faba
local 8dde3b7f9de27358700620ac57f1f4b037d185a606a67ac244bd89787c16910d
local 683b3fa69b25bc3b66446caec94d6b66deafa92877cd275f39cdfab4d5a67ec7
local 941e9aa3f0cd18f4b80cbb56379b84d88a7eafa9954bcd46536ebf9f55c9c7d0
local 19903af74f618926f762a440fe79bbd4936c24afae4db3ea2e9fb273d5453af4
local c4d48d2b515897acaea4133f8cede385b7052906c10f22f08f9c84303adce106
local cbd2029e3e397a06c6af16c43ee858562f1dbb3151f1a3ad786adfc95b31f7ef
local e6811820c6869710d95e34af624b003f5e1ce8092ab492fd07fec9ca53a48ecb
local eaee5368a59851075be69f7180001492786fba9b895e7ae5660f969ca4848e7a
local f658ac2f2cded566bf55d9be7456b3fec03bbde64c414ba5a5b732cfb1779f13
local html
root@ubuntu:/home/ubuntu# docker volume inspect html
[
{
"CreatedAt": "2023-10-04T01:50:24-07:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/html/_data",
"Name": "html",
"Options": null,
"Scope": "local"
}
]