Docker executes a command in a container outside the container

Docker executes a command in a container outside the container

Sometimes we want to execute a command in a container but don't want to enter the container. What to do then?

So the script can be written like this

#!/bin/bash
DOCKER_ID=62f3f40ab240
sudo docker exec -it $DOCKER_ID /bin/bash -c 'cd /packages/detectron && python tools/train.py'

done

Supplementary knowledge: Solve the problem of seamlessly calling shell commands between Docker containers and host machines

I won't say any more nonsense, let's see the solution~

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

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

The above article about how to execute a command in a container outside the container is all I have to share with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Docker exec executes multiple commands
  • How to execute Linux shell commands in Docker
  • How to execute Docker commands without sudo
  • Execute multiple commands after docker run
  • Solve the problem of errors when executing docker daemon commands
  • Docker commands are implemented so that ordinary users can execute them

<<:  MySQL trigger usage scenarios and method examples

>>:  About VSCode formatting JS automatically adding or removing semicolons

Recommend

Specific use of Bootstrap5 breakpoints and containers

Table of contents 1. Bootstrap5 breakpoints 1.1 M...

Solution to Linux CentOS 6.5 ifconfig cannot query IP

Recently, some friends said that after installing...

HTML Tutorial: Collection of commonly used HTML tags (5)

Related articles: Beginners learn some HTML tags ...

Solution to the problem of session failure caused by nginx reverse proxy

A colleague asked for help: the login to the back...

Optimization analysis of Limit query in MySQL optimization techniques

Preface In actual business, paging is a common bu...

Detailed explanation of several solutions for JavaScript interruption requests

Table of contents 1 Promise Interrupt the call ch...

Example of using swiper plugin to implement carousel in Vue

Table of contents vue - Use swiper plugin to impl...

HTML is something that web page creators must learn and master.

What are the benefits of learning HTML? 1: Easily...

How does MySQL achieve master-slave synchronization?

Master-slave synchronization, also called master-...

Analysis of Facebook's Information Architecture

<br />Original: http://uicom.net/blog/?p=762...

WeChat applet implements simple calculator function

This article shares the specific code for the WeC...

MySQL PXC builds a new node with only IST transmission (recommended)

Demand scenario: The existing PXC environment has...

In-depth explanation of modes and environment variables in Vue CLI

Preface In the development of actual projects, we...

td width problem when td cells are merged

In the following example, when the width of the td...