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

25 advanced uses of JS array reduce that you must know

Preface Reduce is one of the new conventional arr...

Docker batch start and close all containers

In Docker Start all container commands docker sta...

MySQL data compression performance comparison details

Table of contents 1. Test environment 1.1 Hardwar...

Detailed explanation of Mysql self-join query example

This article describes the Mysql self-join query....

Introduction to the use of select optgroup tag in html

Occasionally, I need to group select contents. In ...

Solution to the img tag problem below IE10

Find the problem I wrote a simple demo before, bu...

A brief discussion on which fields in Mysql are suitable for indexing

Table of contents 1 The common rules for creating...

Centos7 mysql database installation and configuration tutorial

1. System environment The system version after yu...

Complete steps to quickly build a vue3.0 project

Table of contents 1. We must ensure that the vue/...

Vue-pdf implements online preview of PDF files

Preface In most projects, you will encounter onli...

Setting up VMware vSphere in VMware Workstation (Graphic Tutorial)

VMware vSphere is the industry's leading and ...

Introduction to common MySQL storage engines and parameter setting and tuning

MyISAM, a commonly used storage engine in MySQL c...

JavaScript Snake Implementation Code

This article example shares the specific code of ...

Docker container exits after running (how to keep running)

Phenomenon Start the Docker container docker run ...