Docker exec executes multiple commands

Docker exec executes multiple commands

The docker exec command can execute commands in a running container.

The usage format of the docker exec command is:

docker exec [OPTIONS] container_name COMMAND [ARG...]

OPTIONS description:

-d, execute the command in background mode;

-e, set environment variables

-i, interactive mode

-t, set TTY

-u, username or UID, for example myuser:myusergroup

Usually COMMAND can only be one statement. In order to support the execution of multiple commands, multiple commands need to be connected and handed over to Shell.

The following are examples of using the docker exec command:

sudo docker exec myContainer bash -c "cd /home/myuser/myproject && git fetch ssh://gerrit_server:29418/myparent/myproject ${GERRIT_REFSPEC} && git checkout FETCH_HEAD";
sudo docker exec myContainer bash -c "cd /home/myuser/myproject;git fetch ssh://gerrit_server:29418/myparent/myproject ${GERRIT_REFSPEC};git checkout FETCH_HEAD";

Note: For a paused or stopped container, the docker exec command cannot be executed, and an exception will be thrown as follows:

docker pause myContainer 
docker exec myContainer ...

Supplement: Docker exec host executes commands on the container

Execute naming operations on containers from the host under Docker

docker exec -it 
# Interaction can enter the container; exec can also execute commands on the container on the host;
docker attach 
# You can also enter the container

1. Remote execution command: file operation:

docker exec -d nginx1 touch /etc/1.txt
-d: Background type, create a 1.txt file in the nginx1 container

2. The file copy operation is still cp;

docker cp 1.11.sh nginx1:/root/
# Copy files from the host docker exec nginx1 ls /root
# View the file docker exec nginx1 rm -rf /root/1.11.sh
# Delete files

3. Use diff to view the directory structure of the container;

docker diff nginx1
# View the file structure of the nginx1 container

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • About the problem of starting the Jenkins environment with Docker
  • Install a specific version of Docker for CentOS
  • Detailed explanation of docker basic commands and usage examples
  • A complete guide to deploying Docker projects (summary)
  • Docker image and container import and export operations practice
  • Run Nginx in Docker container and implement reverse proxy
  • Introduction to the implementation principle of Docker exec

<<:  Detailed introduction of Chrome developer tools-timeline

>>:  Common attacks on web front-ends and ways to prevent them

Recommend

How to view and modify the time zone in MySQL

Today I found that a program inserted an incorrec...

Web page experience: planning and design

1. Clarify the design direction <br />First,...

Overview of the Differences between Linux TTY/PTS

When we type a letter on the keyboard, how is it ...

How to View All Running Processes in Linux

You can use the ps command. It can display releva...

Compile CPP files using G++ in Ubuntu

When I used g++ to compile the cpp file for the f...

Steps to install superset under win10 system

Superset is a lightweight self-service BI framewo...

Detailed explanation of custom configuration of docker official mysql image

In order to save installation time, I used the of...

How to use CSS to write different styles according to sub-elements

The effect we need to achieve: What is needed The...

Summary of MySQL database like statement wildcard fuzzy query

MySQL error: Parameter index out of range (1 >...

Detailed explanation of Vue component reuse and expansion

Table of contents Overview Is the extension neces...

Mysql sorting and paging (order by & limit) and existing pitfalls

Sorting query (order by) In e-commerce: We want t...

About the problem of vertical centering of img and span in div

As shown below: XML/HTML CodeCopy content to clip...