Docker使用笔记

1. 获取镜像:

docker pull [options] name[:tag|@digest]

docker pull ubuntu  # 未指定tag时, 使用最新的镜像 :latest
docker pull java:8-jdk
docker images # 查看本地的镜像

2. 创建并运行容器:

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

COMMAND为创建容器后在容器中立即执行的命令.

常用参数:

OPTIONS描述
–attach , -aAttach to STDIN, STDOUT or STDERR
–cpusNumber of CPUs
–detach, -dRun container in background and print container ID
–gpusGPU devices to add to the container (‘all’ to pass all GPUs)
–memory, -mMemory limit
–rmAutomatically remove the container when it exits
–tty , -tAllocate a pseudo-TTY
–volume , -vBind mount a volume. docker run -v /path/on/host:/path/in/container mycontainer:tag
–workdir , -wWorking directory inside the container
–nameAssign a name to the container (就不用通过打容器的id来启动删除容器了…)
docker run -it ubuntu /bin/bash

# 查看所有容器
docker ps -a

# 启动一个已经关闭的容器
docker start container-name/container-id  # 用id和name都行, docer的基本所有命令name和id都能互换

# 进入一个后台运行容器
docker exec -it container-id /bin/bash   # 从容器终端退出, 容器不停止
docker attach container-id  # 从容器终端退出时, 容器会停止

3. 导出、导入和删除容器:

1. 导出本地的容器:

docker export container-id > file-name

2. 从文件导入创建镜像:

docker import file-name [img-name[:tag]]

# 或者这种方式也行:
cat ubuntu.tar | docker import - test/ubuntu:v1  # 这里的 - 是linux里的用法, 代表标准输出的内容(由管道而来)

3. 删除容器:

docker rm container-id
--force , -fForce the removal of a running container (uses SIGKILL)
--link , -lRemove the specified link
--volumes , -vRemove anonymous volumes associated with the container

4. 镜像管理:

1. 查看本地镜像:

docker images

2. 查找镜像:

docker search httpd

3. 删除镜像:

docker rm hello-world # 指定镜像名即可

4. 创建镜像:

1. 从已经创建的容器中更新镜像, 并提交镜像

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

docker commit -m "update image" -a "liangliang" container-id liang/ubuntu:v2  # 最后要指定创建的镜像名字
Name, shorthandDefaultDescription
--author , -aAuthor (e.g., “John Hannibal Smith hannibal@a-team.com”)
--change , -cApply Dockerfile instruction to the created image
--message , -mCommit message
--pause , -ptruePause container during commit
2. 使用Dockerfile指令创建新的镜像
docker build -t liang/ubuntu .
# -t 指定镜像名
# . 指定Dockerfile位置, 为当前位置

Dockerfile是docker使用过程中非常重要的一环, 后续会单独记笔记

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fanqiliang630

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值