docker 命令

官网

run命令

语法格式

docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

实例
n

docker run -d -p 80:80 my_image nginx -g 'daemon off;' # -d(Detached)后台运行 -p指定端口80:80 
docker run -i -t redis /bin/bash # 运行并进入容器
docker exec -it rdis sh #进入正在运行的容器

基础命令

CommandDescription
docker attachAttach local standard input, output, and error streams to a running container
docker buildBuild an image from a Dockerfile
docker builderManage builds
docker checkpointManage checkpoints
docker commitCreate a new image from a container’s changes
docker configManage Docker configs
docker containerManage containers
docker contextManage contexts
docker cpCopy files/folders between a container and the local filesystem
docker createCreate a new container
docker deployDeploy a new stack or update an existing stack
docker diffInspect changes to files or directories on a container’s filesystem
docker engineManage the docker engine
docker eventsGet real time events from the server
docker execRun a command in a running container
docker exportExport a container’s filesystem as a tar archive
docker historyShow the history of an image
docker imageManage images
docker imagesList images
docker importImport the contents from a tarball to create a filesystem image
docker infoDisplay system-wide information
docker inspectReturn low-level information on Docker objects
docker killKill one or more running containers
docker loadLoad an image from a tar archive or STDIN
docker loginLog in to a Docker registry
docker logoutLog out from a Docker registry
docker logsFetch the logs of a container
docker manifestManage Docker image manifests and manifest lists
docker networkManage networks
docker nodeManage Swarm nodes
docker pausePause all processes within one or more containers
docker pluginManage plugins
docker portList port mappings or a specific mapping for the container
docker psList containers
docker pullPull an image or a repository from a registry
docker pushPush an image or a repository to a registry
docker renameRename a container
docker restartRestart one or more containers
docker rmRemove one or more containers
docker rmiRemove one or more images
docker runRun a command in a new container
docker saveSave one or more images to a tar archive (streamed to STDOUT by default)
docker searchSearch the Docker Hub for images
docker secretManage Docker secrets
docker serviceManage services
docker stackManage Docker stacks
docker startStart one or more stopped containers
docker statsDisplay a live stream of container(s) resource usage statistics
docker stopStop one or more running containers
docker swarmManage Swarm
docker systemManage Docker
docker tagCreate a tag TARGET_IMAGE that refers to SOURCE_IMAGE
docker topDisplay the running processes of a container
docker trustManage trust on Docker images
docker unpauseUnpause all processes within one or more containers
docker updateUpdate configuration of one or more containers
docker versionShow the Docker version information
docker volumeManage volumes
docker waitBlock until one or more containers stop, then print their exit codes

docker container

docker container cp -a web-apache:/etc/apache /home/www #拷贝容器web-apache里的/etc/apache 到主机的/home/www目录

### 删除docker中的镜像,我们可以使用如下命令:
docker rmi 镜像id
### 删除docker中的容器可以使用如下命令:

```bash
 docker rm 容器id

使用如下命令可以查看当前正在运行的容器

docker ps

对于已退出的容器,可以使用如下命令进行查看:

docker ps -a

例如:
查看当前正在运行的容器:

查看所有镜像:

查看所有已退出的容器:

下载我们要删除镜像"button-api":

此时发现删除失败,根据提示信息可以知道,当前我们要删除的镜像正在被已停止id为"a4516aee2e7a"的容器所使用,所以我们必须先删除这个已停止的容器,才可以删除镜像。

删除容器之后重新删除"button-api"镜像:

现在发现已删除成功。

重新查询所有镜像,发现"button-api"已被删除:

在删除时还可能遇到如下情况,多个镜像id相同,此时删除也会不成功:

此时我们还可以根据"REPOSITORY"和"TAR"进行删除:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值