我是靠谱客的博主 爱撒娇音响,这篇文章主要介绍Docker常用方法,现在分享给大家,希望可以做个参考。

配置

复制代码
1
2
3
4
5
6
7
8
9
使用nvidia-gpu docker版本小于19.03时,需要额外使用nvidia-docker2软件包 Docker 19.03的发布,不需要使用nvidia-docker2软件包, 因为Docker运行时已将NVIDIA GPU作为设备本地支持,所以安装(或升级)docker版本>=19.03, 再安装nvidia-container-toolkit。 sudo apt-get instal docker sudo apt-get install -y nvidia-container-toolkit

基本命令

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# ---------------------------images----------------------------- docker images # docker image ls # 查看所有的images #下载image:tag,跨平台操作需要指定平台,x86上下载了一晚上的镜像在arm64上不能用,哭晕! docker pull --platform aarch64 image_name:tag #--platform=arm64 ? docker rmi <image-id> # 删除image镜像 # ------------------------------------------------------------- # *************************containers***************************** docker ps -a # docker ps # 查看containers (正在运行的) docker stop <container-name> # stop正在运行的container docker rm <container-name> # remove系统中的container docker run hello-world # 从image创建container, 如果local没有image,就从网上下载。 run: -it /bin/bash #-it interact with the shell / login shell as root #-v map directory #ro read-only mode #-p map port #--name give the container a name. #-d detaches from command line (don't interact with container) #nginx name of the image docker run -v /full/path/to/host:/path/in/container:ro --name foo -p 8080:80 -d nginx #指定--gps, 进去之后可以使用nvidia-smi, 否则‘bash: nvidia-smi: command not found’ docker run -it --rm --name test --gpus all nvidia/cuda:11.3.1-devel-ubuntu18.04 /bin/bash docker exec -it container_name /bin/bash # 运行已经创建的container # ***************************************************************** # save && load 把image保存为本地文件, 并重新加载 docker commit container_id image_name:tag # 保存容器为镜像 docker save -o file_name.tar image_name:tag #保存镜像到本地 docker load -i(nput) file_name.tar #本地文件恢复为镜像 docker save image_id > file_name.tar # 保存到本地镜像文件 file_name.tar docker load < file_name.tar # 加载本地镜像文件 file_name.tar docker tag image_id image_name:tag # 重新load的镜像重命名 # 查看更多命令 docker COMMAND --help

Create a customized image

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#-t give a tag for the image. #'.' look for the Dockerfile in the current directory. docker build -t myappname . #Dockerfile FROM qci-python3 #必须指定一个base image COPY WORKDIR /app ADD . /app RUN pip install --trusted-host pypi.python.org Flask ENV NAME World CMD ["python", "app.py"] ...

基本配置(xiaomi-mace为例)

  1. 创建new container
复制代码
1
2
3
4
5
6
7
8
# Create a container named `mace-dev` docker run -it --privileged -d --name mace-dev -v /dev/bus/usb:/dev/bus/usb --net=host -v /local/path:/container/path -v /usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite
复制代码
1
2
3
4
以上是官方文档给的命令, -v /path/to/host/folder:/path/to/docker/folder 不改变上面命令, 添加自己指定的挂载目录, -v /home/***/**:/home/****
复制代码
1
2
3
4
5
6
7
8
9
# Create a container named `mace-dev` docker run -it --privileged -d --name mace-dev -v /home/***/**/:/home/**** -v /dev/bus/usb:/dev/bus/usb --net=host -v /local/path:/container/path -v /usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite
  1. Create成功, exec

    docker ps 查看containers

复制代码
1
2
3
# Execute an interactive bash shell on the container docker exec -it mace-dev /bin/bash

最后

以上就是爱撒娇音响最近收集整理的关于Docker常用方法的全部内容,更多相关Docker常用方法内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(73)

评论列表共有 0 条评论

立即
投稿
返回
顶部