Docker command
记录在实际环境中我常用的docker命令。 好记性不如烂笔头。
Run ‘docker COMMAND –help’ for more information on a command.
image
列出所有image
docker images
显示指定image详细信息
docker image inspect <image name>
清除没有实例化的image
docker image prune
删除image
docker image rm <image name>
- -f : force removal of the image
从dockerhub拉取一个image
docker image pull <image:tag>
- -q : suppress verbose output
container
根据指定image创建container
docker run -itd -v $(pwd)/path:/path --gpus all --name <container name> <image:tag> /bash
- -i :keep STDIN open even if not attached
- -t : allocate a pseudo-TTY
- -d : run container in background and print container ID
- -v : bind mount a volume
- –gpus : GPU devices to add to the container (‘all’ to pass all GPUs)
- –name : assign a name to the container
- –network : connect a container to a network
- –shm-size : Size of /dev/shm (for the pytorch dataloader)
列出container
docker ps -a
- -a : show all containers (default shows just running)
删除没有使用的container
docker container prune
查看container的详细信息
docker container inspect <container name>
build
使用Dockerfile文件,创建一个image
需要在执行命令的目录下,存在Dockerfile文件
官方不推荐直接使用commit命令直接将container保存成image
docker build -n <container name> -t <name:tag> --shm-size <bytes>
- –shm-size : Size of /dev/shm
- -n : container name
- -t : name:tag, in images
volume
创建一个volume
在数据序列化的时候非常好用,可以用来存放训练用的dataset 并且不同的container可以挂载同一个volume
docker volume create <volume name>
commit
create a new image from a container’s changes
docker commit [options] <container name>
Options:
- -a : author
- -m : commit message
exec
运行存在的container
docker exec -it <container name> /bash
- -i :keep STDIN open even if not attached
- -t : allocate a pseudo-TTY
- -w : working directory inside the container