The docker create command can create a container based on an image. The effect of this command is similar to docker run -d, which creates a container that will run in the background of the system. However, unlike docker run -d, the container created by docker create is not actually started. You still need to execute the docker start command or the docker run command to start the container. In fact, the docker create command is often used to perform necessary settings before starting a container. Here is an example: 1. Create a containerdocker create -it --name mycontainer ubuntu_image bash Example: [root@my ~]# docker create -it --name myvm ubuntgu_image bash 840e4617fac5117c4a142ae6e86ac38e4590a0d6706029abe736843365b16d3640 [root@my ~]# docker ps -a | grep myvm 840e4617fac5 9faf320835640 "/bin/sh -c '/opt/test" 2 minutes ago Created myvm 2. Start the containerdocker start -a -i mycontainer or docker run -it --name mycontainer ubuntu_image bash I won’t go into details about the docker run command here. Supplement: Basic Docker commands 1. Basic commandsdocker version View docker version docker info View docker detailed information docker --help View docker commands 2. Mirror Commanddocker images View docker images PEPOSITORY: Mirrored warehouse source TAG: image tag IMAGE ID: image ID CREATED: Image creation time SIZE: Image size The same repository source can have multiple tags, representing different versions of the repository source. We use REPOSITORY:TAG to define different images. If you do not specify a version tag for an image, for example, if you only use tomcat, Docker will use the tomcat:latest image by default. docker images -a lists all local images docker images -p only displays the image ID docker images --digests displays summary information of the image docker images --no-trunc displays complete image information docker search tomcat searches for tomcat images on Docker Hub STARS: Attention docker search -s 30 tomcat searches for tomcat images with a popularity greater than 30 on Docker Hub docker pull tomcat downloads the tomcat image from Docker Hub. Equivalent to: docker pull tomcat:latest docker commit -m "description of submission" -a "author" container ID target image name to be created: [tag name] submit the container to make it a new image. For example: docker commit -m "new tomcat" -a "lizq" f9e29e8455a5 mytomcat:1.2docker rmi hello-world removes the hello-world image from Docker docker rmi -f hello-world forcefully removes the hello-world image from Docker docker rmi -f hello-world nginx forcefully removes the hello-world image and nginx image from Docker docker rmi -f $(docker images -p) deletes all images using the image ID queried by docker images -p Container Commandsdocker run [OPTIONS] IMAGE creates and starts a container based on the image. IMAGE is the image ID or image name OPTIONS description:--name="container new name": specify a name for the container -d: run the container in the background and return the container ID, that is, start a daemon container -i: run the container in interactive mode, usually used with -t -t: reallocate a pseudo input terminal for the container, usually used with -i -P: random port mapping -p: specify port mapping, there are four formats: ip:hostPort:containerPort ip::containerPort hostPort:containerPort containerPort docker ps lists all currently running containers docker ps -a lists all containers docker ps -l lists recently created containers docker ps -n 3 lists the three most recently created containers docker ps -q only displays the container ID docker ps --no-trunc displays complete information about all currently running containers exit Exit and stop the container Ctrl+p+q only exits the container, does not stop the container docker start container ID or container name to start the container docker restart container ID or container name restarts the container docker stop container ID or container name to stop the container docker kill container ID or container name to force stop the container docker rm Delete container by container ID or container name docker rm -f container ID or container name to force delete the container docker rm -f $(docker ps -a -q) delete multiple containers docker logs -f -t --since --tail container ID or container name to view container logs For example: docker logs -f -t --since="2018-09-10" --tail=10 f9e29e8455a5-f : View real-time logs -t: View the date when the log was generated --since: This parameter specifies the start date of log output, that is, only logs after the specified date are output --tail=10 : View the last 10 logs docker top container ID or container name to view the processes running in the container docker inspect container ID or container name to view the internal details of the container docker attach container ID into the container docker exec container ID to enter the container docker cp container ID: file path in container host path copies files from the container to the host. For example: docker cp f9e29e8455a5:/tmp/yum.log /root The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me. You may also be interested in:
|
>>: JavaScript Dom Object Operations
Table of contents The essence of QR code login Un...
Common usage of Regexp in Mysql Fuzzy matching, c...
DIV+css structure Are you learning CSS layout? Sti...
1. Property List Copy code The code is as follows:...
Maybe some people have not come across this issue ...
This article shares the specific code for impleme...
Use HSSFWorkbook in Apache.POI to export to Excel...
This CSS reset is modified based on Eric Meyers...
Table of contents Chain calls A small case Chain ...
The principle of nginx to achieve resource compre...
Using CSS layout to create web pages that comply w...
Table of contents Example 1 Example 2 Example 3 E...
When I first came into contact with docker, I was...
This article example shares the specific code of ...
Enable WSL Make sure the system is Windows 10 200...