The docker operation of docker enters the container running in the background

When we run the docker container, we use the -d parameter to run the container in the background.
At this time, we can use the docker ps command to know which programs are running in the background.
 

 

How do we get into the docker container?
 
 
1: Use the docker attach command
We use
 
docker attach db3 或者 docker attach d48b21a7e439

 

 
db3 is the NAMES of the background container, d48b21a7e439 is the process ID CONTAINER ID of the container
Then go into the ssh interface of the container.
But it has a disadvantage, as soon as the connection is terminated, or the exit command is used, the container will exit the background running
 
 
2: Use the docker exec command
After this command uses the exit command, it will not exit the background. Generally, this command is used. The usage method is as follows
 
docker exec -it db3 /bin/sh 或者 docker exec -it d48b21a7e439 /bin/sh

 

 
db3 is the NAMES of the background container, d48b21a7e439 is the process ID CONTAINER ID of the container
 /bin/sh is a fixed spelling
it can also enter this container

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326285673&siteId=291194637