0
点赞
收藏
分享

微信扫一扫

4-Docker命令之docker exec

1.docker exec介绍

docker exec命令是用来在运行中的容器运行命令

2.docker exec用法

docker exec [参数]

[root@centos79 ~]# docker exec --help

Usage:  docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

Execute a command in a running container

Aliases:
  docker container exec, docker exec

Options:
  -d, --detach               Detached mode: run command in the background
      --detach-keys string   Override the key sequence for detaching a container
  -e, --env list             Set environment variables
      --env-file list        Read in a file of environment variables
  -i, --interactive          Keep STDIN open even if not attached
      --privileged           Give extended privileges to the command
  -t, --tty                  Allocate a pseudo-TTY
  -u, --user string          Username or UID (format: "<name|uid>[:<group|gid>]")
  -w, --workdir string       Working directory inside the container
[root@centos79 ~]#

3.实例

3.1.进入运行中的容器

命令:

docker exec -it a498 /bin/bash

[root@centos79 ~]# docker ps -a | grep a498
a4984c765518   daocloud.io/library/centos:latest   "bash"                    20 hours ago   Up 20 minutes                                                                                          centos-ztj
[root@centos79 ~]# docker exec -it a498 /bin/bash
[root@a4984c765518 /]# hostname
a4984c765518
[root@a4984c765518 /]#

3.2.查看运行容器中的目录

命令:

docker exec a498 ls /

[root@centos79 ~]# docker exec a498 ls /
bin
dev
etc
home
lib
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
[root@centos79 ~]#



举报

相关推荐

0 条评论