Pull the imagedocker pull [options] name [:tag] means pulling the image from the repository. options is a parameter. tag is a version. Run the image (generate a container)docker run [options] image [:tag] [command] [arg…] Run a container to create a container using the image as a template options operation tag version command command to execute when running arg parameter
After the docker container completes the task, it will be in the exited state. If you want to put the container in the up state, you can use the following command, such as: docker run -dit nginx:latest /bin/bash Start the containerdocker start container ID Entering the containerdocker attach container id docker exec -it container ID /bin/bash docker exec -it container name bash View All Mirrors List images: Exit the container If you want to exit normally without closing the container, press (Ctrl+P+Q) to exit the container. If you use exit to exit, the container will be closed after exiting. Restarting the containerRestart the container using the (docker restart container id) command View All Containersdocker container ls docker ps (view running containers) docker ps -a (view all containers) Deleting a container We can also use the docker container rm command to delete a specified container, or simply write the docker rm command to delete the container. However, 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) Batch delete stopped containers in DockerMethod 1: #Show all containers, filter out containers in the Exited state, and retrieve the IDs of these containers. sudo docker ps -a|grep Exited|awk '{print $1}' #Query all containers, filter out containers in Exited state, list container IDs, and delete these containers sudo docker rm `docker ps -a|grep Exited|awk '{print $1}'` Method 2: #Delete all non-running containers (the running ones cannot be deleted, and the non-running ones will be deleted together) sudo docker rm $(sudo docker ps -a -q) Method 3: #According to the status of the container, delete the container in the Exited state sudo docker rm $(sudo docker ps -qf status=exited) Method 4: #After Docker version 1.13, you can use the docker containers prune command to delete isolated containers. vscode remotely connects to the container in the server via ssh1. Run the ubuntu image to create a container: docker run -it ubuntu 2. Enter the container and set the container root password
3. Install ssh service apt-get update apt-get install openssh-server 4. Modify the ssh configuration to allow root login. Generally, the root account is used to enter the container, but ssh prohibits the root account from using a password to log in remotely by default, so you need to modify the ssh configuration file to allow it: vim /etc/ssh/sshd_config Change the value of PermitRootLogin from withoutPassword to yes (remove the leading #) If you don't have vim, you can install it: apt-get install vim 5. Save container modifications and generate a new image docker commit <container_id> <new_image_name> For example, docker commit <container_id> ubuntu-ssh 6. Exit the current container and run the new image just saved (this time you need to map the port and run it in the background) exit (the container will be closed after exit) docker run -dit -p 8008:22 ubuntu-ssh (8008 is the port number, which is used when connecting via ssh) 7. Enter the container running in the background through the exec command docker exec -it container_id /bin/bash #exec is to enter an existing container, run is to create a new container 8. Start ssh service sudo service ssh start In addition (stop restart is shutdown and restart respectively) 9. Determine whether the startup is successful Enter in the terminal: ps -e|grep ssh to check whether it is started successfully. If there is sshd, it means that it is started successfully. The output is as follows: $ sudo ps -e | grep ssh 4031 ? 00:00:00 sshd------corresponding to the server-side sshd, indicating that the ssh-server is started 10. Exit the container but don’t shut it down exit (because we enter the container through the exec command, exit does not exit the container, the container will run in the background) 11 Remote Connection ssh root@host_id -p 8008 This is the end of this article about how to set up vscode remote connection to server docker container. For more relevant vscode remote connection to docker content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: HTML discount price calculation implementation principle and script code
>>: Responsive Web Design Learning (2) — Can videos be made responsive?
XML is designed to describe, store, transmit and ...
Table of contents background CommonsChunkPlugin s...
Introduction to Selenium Grid Although some new f...
yum or rpm? The yum installation method is very c...
Table of contents Preface 1. Configure intranet D...
There are many XHTML tags: div, ul, li, dl, dt, d...
routing vue-router4 keeps most of the API unchang...
INSERT INTO hk_test(username, passwd) VALUES (...
It is very simple to build a kong cluster under t...
1. Previous versions yum remove docker docker-cli...
Use HTML to create complex tables. Complex tables...
mysql 8.0.22 winx64 installation and configuratio...
Table of contents 01-Event Bubbling 1.1- Introduc...
1. mysql export file: SELECT `pe2e_user_to_compan...
Table of contents 1. What is componentization? 2....