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

react-beautiful-dnd implements component drag and drop function

Table of contents 1. Installation 2.APi 3. react-...

Make your website automatically use IE7 compatibility mode when browsing IE8

Preface To help ensure that your web pages have a ...

New usage of watch and watchEffect in Vue 3

Table of contents 1. New usage of watch 1.1. Watc...

Details of watch monitoring properties in Vue

Table of contents 1.watch monitors changes in gen...

Install MySQL (including utf8) using Docker on Windows/Mac

Table of contents 1. Docker installation on Mac 2...

Master-slave synchronization configuration of Mysql database

Table of contents Mysql master-slave synchronizat...

CSS realizes process navigation effect (three methods)

CSS realizes the process navigation effect. The s...

Explanation of Dockerfile instructions and basic structure

Using Dockerfile allows users to create custom im...

Markup Languages ​​- Lists Again

Click here to return to the 123WORDPRESS.COM HTML ...

Detailed explanation of component communication in react

Table of contents Parent component communicates w...

Adobe Brackets simple use graphic tutorial

Adobe Brackets is an open source, simple and powe...

How to modify the default network segment of Docker0 bridge in Docker

1. Background When the Docker service is started,...