Docker enables seamless calling of shell commands between container and host

Docker enables seamless calling of shell commands between container and host

As shown below:

nsenter -t 1 -m -u -n -i sh -c "echo hello world!"

Add privilege permissions to the docker container and set pid: "host"

Supplement: Execute shell scripts or commands in docker containers on the host

Common command forms:

docker exec -it master /bin/bash -c 'echo $PATH'
docker exec -it master /bin/bash -c 'cd /home/bigdata/shell && ./test.sh'

If the shell script involves environment variables, or prompts JAVA_HOME is not set, you can add the following command to the script

export JAVA_HOME=jdk path

Supplement: Run the commands executed in the container in Docker on the Docker host

The script is as follows:

docker exec -u root xxx(container name) bash -c 'command 1 && command 2'

A practical example is as follows:

docker exec -u root mycentos bash -c 'mkdir /home/test.txt && chmod 777 /home/test.txt && runuser - oracle -c "rm -rf /home/test.txt"'

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:
  • Detailed explanation of creating a MySQL container with Docker and connecting to the container through the command line
  • Docker solves the problem that JDK's jmap and other commands cannot be used in openjdk containers
  • Detailed explanation of running multiple commands in Docker container (supervisor)
  • Summary of Docker's commonly used commands for clearing container images
  • Detailed explanation of docker container creation and common operation commands

<<:  Summary of tips for making web pages

>>:  We're driving IE6 to extinction on our own

Recommend

MySql 8.0.11 installation and configuration tutorial

Official website address: https://dev.mysql.com/d...

Mobile Internet Era: Responsive Web Design Has Become a General Trend

We are in an era of rapid development of mobile In...

WeChat applet uses the video player video component

This article example shares the specific code of ...

Native JS to achieve sliding button effect

The specific code of the sliding button made with...

CSS3 realizes various graphic effects of small arrows

It’s great to use CSS to realize various graphics...

MySQL 5.7 and above version download and installation graphic tutorial

1. Download 1. MySQL official website download ad...

How to use Docker plugin to remotely deploy projects to cloud servers in IDEA

1. Open port 2375 Edit docker.service vim /lib/sy...

MySQL functional index optimization solution

When using MySQL, many developers often perform f...

JavaScript implements simple calculator function

This article shares the specific code of JavaScri...

js to achieve simple drag effect

This article shares the specific code of js to ac...

CSS code to distinguish ie8/ie9/ie10/ie11 chrome firefox

Website compatibility debugging is really annoyin...

Measured image HTTP request

Please open the test page in a mainstream browser...