Setting Method of vscode Remote Connection Server docker Container
- 2021-11-10 11:14:52
- OfStack
Pull mirror image
docker pull [options] name [:tag] Indicates pulling an image from a warehouse options Is a parameter tag Is the version
Run mirroring (produces 1 container)
docker run [options] image [:tag] [command] [arg … ]
Run 1 container with mirror as template to create container options operation tag version command command executed at runtime arg parameters
Options Options Abbreviation
detach-d runs the container in the background and prints the container id.
interactive-i should keep the standard input open even if it is not connected. 1 is used with-t.
tty-t assigns a pseudo tty, which is generally used with-i.
The docker container will be in the exited state after the task is completed. If you want the container to be in the up state, you can use the following commands, such as:
Start a container in the background in interactive mode using mirrored nginx: latest, and execute the/bin/bash command inside the container.
docker run -dit nginx:latest /bin/bash
Startup container
docker start Container ID
Enter the container
docker attach Container ID
docker exec -it Container ID /bin/bash
docker exec -it Container name bash
View all images
List the mirrors:
docker images [OPTIONS] [REPOSITORY[:TAG]]
Exit container
To exit normally without closing the container, press (Ctrl+P+Q) to exit the container
If you exit using exit, the container is closed after the exit
Restart the container
Restart the container using the (docker restart container id) command
View all containers
docker container ls
docker ps ( View the running container)
docker ps -a ( View all containers)
Delete a container
We can also use the command docker container rm to delete a specified container, or simply write the command docker rm to delete a container, but it is not allowed to delete a running container, so if you want to delete it, you must stop the container first.
docker rm container_id
When we need to delete all containers in batches, we can use the following command:
docker rm $(docker ps -q)
Bulk Delete Stopped Containers in docker
Method 1:
# Show all containers and filter out Exited State of the containers, and take out the ID ,
sudo docker ps -a|grep Exited|awk '{print $1}'
# Query all containers and filter out Exited Status of the container, list the containers ID Delete these containers
sudo docker rm `docker ps -a|grep Exited|awk '{print $1}'`
Method 2:
# Delete all containers that are not running (those that are already running cannot be deleted, and those that are not running will 1 Has been deleted)
sudo docker rm $(sudo docker ps -a -q)
Method 3:
docker run [options] image [:tag] [command] [arg … ]
0
Method 4:
docker run [options] image [:tag] [command] [arg … ]
1
vscode remotely connects containers in the server through ssh
1. Run the ubuntu image to create the container:
docker run [options] image [:tag] [command] [arg … ]
2
2. Enter the container and set the container root password
Modify the container's root password: passwd
The password is set to 123456
3. Install the ssh service
apt-get update
apt-get install openssh-server
4. Modify ssh configuration to allow root login. Generally, root account is used when entering the container, but ssh prohibits root account from logging in remotely with password by default, so it is necessary to modify ssh configuration file to allow:
docker run [options] image [:tag] [command] [arg … ]
4
5. Save container modifications and generate new images
docker run [options] image [:tag] [command] [arg … ]
5
6. Exit the current container and run the new image you just saved (this run requires port mapping and running in the background)
docker run [options] image [:tag] [command] [arg … ]
6
7. Enter the container running in the background through the exec command
docker run [options] image [:tag] [command] [arg … ]
7
8. Start the ssh service
sudo service ssh start
In addition (stop restart is closed and restarted respectively)
9. Determine whether the startup was successful
Enter: ps-egrep ssh in the terminal to check whether the startup is successful. If there is sshd, it means the startup is successful.
The output is as follows:
docker run [options] image [:tag] [command] [arg … ]
9
10 Exit the container but do not close it
exit (because we entered the container through the exec directive, the container does not exit the container at exit, and the container runs in the background)
11 Remote Connection
ssh root@host_id -p 8008