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

How to use the Linux nl command

1. Command Introduction nl (Number of Lines) adds...

SELinux Getting Started

Back in the Kernel 2.6 era, a new security system...

Detailed example of Linux all-round system monitoring tool dstat

All-round system monitoring tool dstat dstat is a...

Problems and solutions of using jsx syntax in React-vscode

Problem Description After installing the plugin E...

2 reasons why html-css tag style setting does not work

1 CSS style without semicolon ";" 2 Tags...

Win10 uses Tsinghua source to quickly install pytorch-GPU version (recommended)

Check whether your cuda is installed Type in the ...

Vue component to realize carousel animation

This article example shares the specific code of ...

MySQL 8.0.19 Installation Tutorial

Download the installation package from the offici...

Analyze how to automatically generate Vue component documentation

Table of contents 1. Current situation 2. Communi...

A brief discussion on several advantages of Vue3

Table of contents 1. Source code 1.1 Monorepo 1.2...

How to remove spaces or specified characters in a string in Shell

There are many methods on the Internet that, alth...

Docker Basic Tutorial: Detailed Explanation of Dockerfile Syntax

Preface Dockerfile is a script interpreted by the...