Run

1. Running a docker in the background

 
docker run -d centos /bin/sh -c "while true;do echo is running; sleep 1;done"
 # -d Run the container in the background
 # /bin/sh Specifies the bash interpreter using centos
 # -c Run a shell command
 # "while true;do echo is running; sleep 1;done" is running in the linux background, running once per second
 
 docker ps # check container process 
 docker logs -f container id/name # log information for uninterrupted print container 
 docker stop centos # stop container

2. Start a bash terminal and allow users to interact

 docker run --name mydocker -it centos /bin/bash
 # --name defines a name for the container
 # -i keep the standard input of the container open
 # -t Let Docker assign a pseudo terminal and bind it to the standard input of the container
 # /bin/bash Specify the docker container to interact with the shell interpreter

When using docker run to create a container, the steps that Docker runs in the background are as follows:

1. Check if the specified image exists locally. If it does not exist, download it from the public repository.

2. Create and start a container with an image

3. Allocate a file system and hang on a read-write layer outside the read-only mirror layer

4. Bridge a virtual interface to the container from the bridge interface configured by the host.

5. Configure an ip address from the address pool to the container

6. Execute the user-specified application

7. The container is terminated after execution

3.Restart a stopped container

4.commit custom image

5.External access container

Last updated