search
HomeOperation and MaintenanceDockerWhat is the difference between create and run in docker

In docker, both the create command and the run command can create a new container. The difference is that the create command creates a new container but does not start it, while the run command creates a new container and runs a command.

What is the difference between create and run in docker

The operating environment of this tutorial: linux7.3 system, docker-1.13.1 version, Dell G3 computer

What is the difference between create and run in docker

The following is the purpose of these commands:

  • The docker create command creates a brand new one from a Docker image container. However, it won't run it immediately.

  • The docker start command will start any stopped containers. If you created a container using the docker create command, you can use this command to start it.

  • The docker run command is a combination of create and start as it creates a new container and starts it immediately. In fact, the docker run command can even pull the image from Docker Hub if it cannot find the above image on your system.

Let's look at it with examples so you can understand things more clearly.

Let's see it through an example

If you want to follow the example, make sure you have Docker installed.

Suppose you use the docker pull ubuntu command to download the Ubuntu image from Docker Hub.

You can view all available Docker images on your system. In this example, I only have ubuntu (to avoid confusion):

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              775349758637        5 weeks ago         64.2MB

Now, create a new docker container named container-1 using the docker create command:

# docker create --name container-1 ubuntu
6a81a998658e9e0d3b612ee65b07d76a45d79812d860baf3f1cbc60fe997ebec

You can see it A new container has been created. If you try to view all running containers, you won't see container-1 because although it was created, it was never started.

# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

If you check all containers, whether they are running or not, you will see that container-1 has "created" status:

# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
6a81a998658e        ubuntu              "/bin/bash"         18 seconds ago      Created                                 container-1

Now, let us use the docker run command to create and run A container named container-2:

# docker run -it -d --name container-2 ubuntu bash
6391c1a0cac6c9f5fc6f5cfb05d75a22c208e63223c3b231035a40a4b134c521

You can see that container-2 is running because its status is "Started":

# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
6391c1a0cac6        ubuntu              "bash"              About a minute ago   Up About a minute                       container-2

Let's stop this running Container:

# docker stop container-2
container-2
# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
6391c1a0cac6        ubuntu              "bash"              2 minutes ago       Exited (0) 28 seconds ago                       container-2
6a81a998658e        ubuntu              "/bin/bash"         3 minutes ago       Created                                         container-1

Now we have a stopped container, you can start it again using docker start command:

# docker start container-2
container-2
# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
6391c1a0cac6        ubuntu              "bash"              2 minutes ago       Up 2 seconds                            container-2

But, what happens to container-1 created using docker create command ? You can start this container using docker start command and then use docker exec to run specific stuff.

Recommended learning: "docker video tutorial"

The above is the detailed content of What is the difference between create and run in docker. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Kubernetes vs. Docker: Understanding the RelationshipKubernetes vs. Docker: Understanding the RelationshipMay 12, 2025 am 12:16 AM

The relationship between Docker and Kubernetes is: Docker is used to package applications, and Kubernetes is used to orchestrate and manage containers. 1.Docker simplifies application packaging and distribution through container technology. 2. Kubernetes manages containers to ensure high availability and scalability. They are used in combination to improve application deployment and management efficiency.

Docker: The Container Revolution and Its ImpactDocker: The Container Revolution and Its ImpactMay 10, 2025 am 12:17 AM

Docker solves the problem of consistency in software running in different environments through container technology. Its development history has promoted the evolution of the cloud computing ecosystem from 2013 to the present. Docker uses Linux kernel technology to achieve process isolation and resource limitation, improving the portability of applications. In development and deployment, Docker improves resource utilization and deployment speed, supports DevOps and microservice architectures, but also faces challenges in image management, security and container orchestration.

Docker vs. Virtual Machines: A ComparisonDocker vs. Virtual Machines: A ComparisonMay 09, 2025 am 12:19 AM

Docker and virtual machines have their own advantages and disadvantages, and the choice should be based on specific needs. 1.Docker is lightweight and fast, suitable for microservices and CI/CD, fast startup and low resource utilization. 2. Virtual machines provide high isolation and multi-operating system support, but they consume a lot of resources and slow startup.

Docker's Architecture: Understanding Containers and ImagesDocker's Architecture: Understanding Containers and ImagesMay 08, 2025 am 12:17 AM

The core concept of Docker architecture is containers and mirrors: 1. Mirrors are the blueprint of containers, including applications and their dependencies. 2. Containers are running instances of images and are created based on images. 3. The mirror consists of multiple read-only layers, and the writable layer is added when the container is running. 4. Implement resource isolation and management through Linux namespace and control groups.

The Power of Docker: Containerization ExplainedThe Power of Docker: Containerization ExplainedMay 07, 2025 am 12:07 AM

Docker simplifies the construction, deployment and operation of applications through containerization technology. 1) Docker is an open source platform that uses container technology to package applications and their dependencies to ensure cross-environment consistency. 2) Mirrors and containers are the core of Docker. The mirror is the executable package of the application and the container is the running instance of the image. 3) Basic usage of Docker is like running an Nginx server, and advanced usage is like using DockerCompose to manage multi-container applications. 4) Common errors include image download failure and container startup failure, and debugging skills include viewing logs and checking ports. 5) Performance optimization and best practices include mirror optimization, resource management and security improvement.

Kubernetes and Docker: Deploying and Managing Containerized AppsKubernetes and Docker: Deploying and Managing Containerized AppsMay 06, 2025 am 12:13 AM

The steps to deploy containerized applications using Kubernetes and Docker include: 1. Build a Docker image, define the application image using Dockerfile and push it to DockerHub. 2. Create Deployment and Service in Kubernetes to manage and expose applications. 3. Use HorizontalPodAutoscaler to achieve dynamic scaling. 4. Debug common problems through kubectl command. 5. Optimize performance, define resource limitations and requests, and manage configurations using Helm.

Docker: An Introduction to Containerization TechnologyDocker: An Introduction to Containerization TechnologyMay 05, 2025 am 12:11 AM

Docker is an open source platform for developing, packaging and running applications, and through containerization technology, solving the consistency of applications in different environments. 1. Build the image: Define the application environment and dependencies through the Dockerfile and build it using the dockerbuild command. 2. Run the container: Use the dockerrun command to start the container from the mirror. 3. Manage containers: manage container life cycle through dockerps, dockerstop, dockerrm and other commands.

Docker and Linux: Building Portable ApplicationsDocker and Linux: Building Portable ApplicationsMay 03, 2025 am 12:17 AM

How to build portable applications with Docker and Linux? First, use Dockerfile to containerize the application, and then manage and deploy the container in a Linux environment. 1) Write a Dockerfile and package the application and its dependencies into a mirror. 2) Build and run containers on Linux using dockerbuild and dockerrun commands. 3) Manage multi-container applications through DockerCompose and define service dependencies. 4) Optimize the image size and resource configuration, enhance security, and improve application performance and portability.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Atom editor mac version download

Atom editor mac version download

The most popular open source editor