docker from entry to entry

0. Start Docker

systemctl start docker # 启动docker,或者使用 service docker start
systemctl stop docker # 关闭docker
systemctl restart docker # 重启docker
systemctl status docker #  查看docker状态

1. Docker pulls the image

docker search ImageName # 搜索镜像
docker pull ImageName # 拉取镜像
docker rmi ImageName # 删除镜像
docker rm ContainerName # 删除容器(少个i)

example

docker pull hangvane/cuda-conda-desktop:ubuntu16.04

There are multiple image sources in Docker Hub: Docker Hub homepage

2. Docker view image

docker images

3. Docker creates a new container

docker run --name ContainerName -it ImageName /bin/bash

Parameter description: -it = -i -t

  • -t means to specify a terminal in the new container (terminal)
  • -i means the container is interactive
  • ContainerID specifies the container name, and ImageName represents the image name
  • /bash/bin means to start the bash shell in the container

example

docker run --name XinxinLi -it --gpu='device=0, 1' dzw001/cuda11.1-cudnn8-python3.6-pytorch1.8.1-ubuntu18.04 /bin/bash
# 中间插个 --gpu 指定特定显卡

4. Docker into the container

docker start ContainerID # 启动docker容器,使用restart则是重启
docker exec -it ContainerID /bin/bash # 进入容器的交互界面

5. Docker exits and closes the container

exit # 或者使用Ctrl + D
docker stop ContainerID

6. Docker view container

docker ps # 查看正在运行的容器
docker container ls # 查看正在运行的容器(list)
docker ps -a # 查看所有容器(all)

7. File transfer between Docker and the host

docker cp 宿主机路径 容器ID:容器里的路径 # 本地宿主机往docker容器里传文件
docker cp 容器ID:容器里的路径 宿主机路径# 与上面正好相反

example

docker cp /home/ubuntu/XinxinLi/downloads/sewer-ml.zip 7df165187730:/home/xinxinli/
# 本地物理机往容器ID为7df165187730的目录/home/xinxinli/传递文件sewer-ml.zip

8. Import/export images

docker export 容器ID>>文件名.tar
cat 文件名.tar | docker import - 镜像用户/镜像名:镜像版本

Appendix A. Source change jump in ubuntu container:

ubuntu20.04 replace source and download pytorch

Guess you like

Origin blog.csdn.net/qq_41731507/article/details/127983162