Docker enters the container and executes commands in the container

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 -itis sufficient.

1.2 COMMAND parameters:

commandRefers to the shelltype, there are common bash、sh、zsh, but most of the Linux system is the default bashtype, the new Mac OSsystem, 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] webserverand 91af26862191all containers 唯一标识, which it can use.

General inside the container Linuxis a streamlined version, there is no less 、cat 、vim/visuch orders, if required, can install their own, it comes with a default APTcommand.

4. Recommended configuration

If you are learning to use, you can choose to install other commands inside the container 如果是正式环境的话推荐把各个容器的配置文件映射到宿主机器上(也就是装 Docker 的机器)方便维护.

Guess you like

Origin blog.csdn.net/peng2hui1314/article/details/107985381