table of Contents
1. Syntax:
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
1.1 OPTIONS parameter description:
-i
: Keep the standard input ( STDIN
) of the container always open, even if no instructions are entered (no additional)
-t
: Assign a terminal so that we can use commands to operate
-d
: Separate mode, let the commands run in the background (referring to the host background) .
[Note] general use -it
is sufficient.
1.2 COMMAND parameters:
command
Refers to the shell
type, there are common bash、sh、zsh
, but most of the Linux system is the default bash
type, the new Mac OS
system, the default is no longer bash
, but zsh
.
2. View the running container
docker ps
The results are as follows:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91af26862191 nginx "/docker-entrypoint.…" 7 hours ago Up 2 hours 0.0.0.0:80->80/tcp webserver
3. Use exec to enter the container
docker exec -it webserver bash
#或
docker exec -it 91af26862191 bash
You can enter the command line interface inside the container.
[Note] webserver
and 91af26862191
all containers 唯一标识
, which it can use.
General inside the container Linux
is a streamlined version, there is no less 、cat 、vim/vi
such orders, if required, can install their own, it comes with a default APT
command.
4. Recommended configuration
If you are learning to use, you can choose to install other commands inside the container 如果是正式环境的话推荐把各个容器的配置文件映射到宿主机器上(也就是装 Docker 的机器)方便维护
.