docker run
Run a command in a new container
启动一个新的容器,一般在docker pull之后首次运行此image
-i 保持stdout打开
-t 打开一个tty
-d 后台运行, 不加-d时运行完可能会自动结束
Ctrl+P+Q 退出tty并保持后台运行
docker start
Start one or more stopped containers
新的容器退出后(比如关机重启了),如果仍然使用docker run xxxx的话,以前的操作内容不会保存。此时可以使用docker start启动历史的容器
上图中使用了两次run mongo, 因此有两个container id, 使用docker start仍能看到历史数据.
docker restart
重启一个运行中的容器
docker exec
Run a command in a running container
容器启动后,使用docker ps获得运行中的容器id, 然后使用docker exec进入此运行中的容器。如果有多个参数,不要加“”
后台运行使用-d, 不是使用&
docker top
显示容器内运行中的进程
docker stats
查看容器内存使用量, 相当于linux shell 中的TOP /iostat
docker commit
Create a new image from a container's changes
在容器的基础上创建新的image, 可以指定自己的imageName:tag。
docker build
从DockerFile创建image, DockerFile中可以使用apt|yum安装特定的软件
docker build -f ./Dockerfile -t registry-qa.com/data-service:latest .
docker push
-Push an image or a repository to a registry
将自己的image推到仓库,方便分享
podman push registry-qa.com/data-service:test
push的时候是带域名和tag的, 可以指定仓库地址
docker image prune
Remove unused images
清理磁盘空间
还有其他类型的prune命令:
https://docs.docker.com/engine/reference/commandline/system_prune/docker system prune
docker network ls/ inspect
查看桥接后的内网ip
卷挂载 -保存历史数据的另一种方法 https://www.cnblogs.com/lighten/p/6900556.html
容器编排,批量启动?
docker inspect
docker logs
结果包含了stderr stdout的内容,比如nginx container的access/error日志默认就是映射到/dev/stdout /dev/stderr
可以通过docker inspect xxxx | grep log 找到宿主机的真实日志文件
可以使用docker run -v指定目录的挂载 -v xxxx:/var/logs/nginx/error.log
默认日志文件大小5*20M=100M
https://docs.docker.com/config/containers/logging/json-file/ daemon.json中配置
docker logs -f containerx
docker inspect nginx | grep log
"LogPath": "/var/lib/docker/containers/b43d99c4ce8ccd4ff97599dedb42b9166a0c46221a0f0e0a40a400e9cca5964f/b43d99c4ce8ccd4ff97599dedb42b9166a0c46221a0f0e0a40a400e9cca5964f-json.log"
docker compose挂载示例:
podman
https://www.redhat.com/sysadmin/podman-windows-wsl2
https://download.opensuse.org/repositories 网速坑爹,国内镜像不包含repositories仓库,只能用德国的镜像站了 https://mirrors.opensuse.org/
使用cgroupfs替换systemd, 这样在WSL中可以直接启动image了,不用安装docker desktop cp /usr/share/containers/containers.conf /etc/containers/