Usage instructions for the docker create command

Usage instructions for the docker create command

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 container

docker 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 container

docker 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 commands

docker version View docker version

docker info View docker detailed information

docker --help View docker commands

2. Mirror Command

docker 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.2

docker 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 Commands

docker 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:
  • A brief discussion on the problem of Docker run container being in created state
  • Solve the problem after adding --subnet to Docker network Create
  • docker compose idea CreateProcess error=2 The system cannot find the specified file

<<:  Detailed explanation of two methods to solve a bug in the justify-content: space-between alignment of flex layout

>>:  JavaScript Dom Object Operations

Recommend

A brief discussion on the principle of js QR code scanning login

Table of contents The essence of QR code login Un...

Common usage of regular expressions in Mysql

Common usage of Regexp in Mysql Fuzzy matching, c...

HTML structured implementation method

DIV+css structure Are you learning CSS layout? Sti...

DIV common attributes collection

1. Property List Copy code The code is as follows:...

Web design skills: iframe adaptive height problem

Maybe some people have not come across this issue ...

Implementing carousel with native JavaScript

This article shares the specific code for impleme...

Java uses Apache.POI to export HSSFWorkbook to Excel

Use HSSFWorkbook in Apache.POI to export to Excel...

HTML 5 Reset Stylesheet

This CSS reset is modified based on Eric Meyers...

Detailed explanation of jQuery chain calls

Table of contents Chain calls A small case Chain ...

About Nginx gzip configuration

The principle of nginx to achieve resource compre...

Web page creation basic declaration document type description (DTD

Using CSS layout to create web pages that comply w...

Share JS four fun hacker background effect codes

Table of contents Example 1 Example 2 Example 3 E...

How to connect to docker server using ssh

When I first came into contact with docker, I was...

js code to realize multi-person chat room

This article example shares the specific code of ...

How to install WSL2 Ubuntu20.04 on Windows 10 and set up the docker environment

Enable WSL Make sure the system is Windows 10 200...