• Reach us at connect@buildpiper.io

Logo
  • Home
  • Features
    • Microservices Delivery
    • Secure CI/CD Pipelines
    • Managed Security & Observability
    • Managed Kubernetes
  • Resources
    • Documentation
    • Blog
    • Release Notes
    • Walk Through
    • Workshop
    • Podcast & Shows
    • Ebook
    • Case Studies
  • Contact Us

Simplifying Containerization with Docker Run Command

Docker run command
  • February 15 2023
  • Ruchita Varma

Docker run is a fundamental command for running applications in Docker containers. Before you start with Docker, it’s important to know about some important commands. In this blog, we will explain the basic syntax of the Docker run command and explore some of its most common options to help you get started with running and managing Docker containers. Here, you will learn how to use the docker run command to create and start a Docker container from an image with various configuration options.

What is Docker run command?

The ‘docker run’ command is used to create and start a new container from a Docker image. The basic syntax of the ‘docker run’ command is as follows:                           docker run [OPTIONS] IMAGE [COMMAND] [ARG…] where,

  • OPTIONS: optional flags that configure the behaviour of the container, such as setting environment variables, mounting volumes, etc.
  • IMAGE: the name of the Docker image to be run.
  • COMMAND: the command to be executed when the container is started. If not provided, the default command specified in the Docker image will be used.
  • ARG: optional arguments passed to the command.

For example, to start a new container from the official Nginx image and map the container’s port 80 to the host’s port 8080, you would run the following command:                                                                      docker run -p 8080:80 nginx This command will create a new container based on the Nginx image, start it, and map port 80 inside the container to port 8080 on the host.

Examples of Docker Run Command

Here are some docker run command examples that you must look at:

1. Running a simple image

docker run busybox echo “Hello, World!”

This command runs a new container from the ‘busybox’ image and executes the ‘echo’ command with the argument “Hello, World!”. 2. Setting Environment

docker run -e MY_VAR=value busybox env

This command sets an environment variable ‘MY_VAR’ to the value “value” and runs a new container from the ‘busybox’ image. The ‘env’ command is executed to display the list of environment variables in the container. 3. Mounting a Volume                docker run -v /host/directory:/container/directory busybox ls /container/directory This command mounts a host directory ‘/host/directory’ to the container directory ‘/container/directory’ and runs a new container from the ‘busybox’ image. The ‘ls’ command is executed to list the contents of the container directory. 4. Running a container in the background           docker run -d nginx The command docker run -d nginx starts a Docker container based on the official Nginx image in detached mode. The -d flag runs the container in the background and the nginx argument specifies the image name to use for the container. This command will pull the Nginx image from Docker Hub if it is not already present on your local machine, create a container based on that image, and start it in the background. 5. Running a container with a specific name                                        docker run –name my-container busybox echo “Hello, World!” This command runs a new container with the specified name “my-container” from the busybox image and executes the echo command with the argument “Hello, World!”. Here’s how we enabled Wheebox, a leading Global online remote proctored testing firm, to achieve a 100% reduction in production time. Take a look!

Options Available for executing Docker Run Command

Some commonly used options for executing the docker run command inside container:

  • -it: Runs the container in interactive mode, allowing you to interact with the container through the command line.
  • -d: Runs the container in the background.
  • –name: Specifies a name for the container.
  • –rm: Automatically removes the container when it exits.
  • -p: Maps a host port to a container port.
  • -e: Sets an environment variable inside the container.
  • -v: Mounts a host volume inside the container.

For example, to run an Ubuntu image and launch a shell inside the container, you could use the following command:   docker run -it ubuntu /bin/bash

How to Start a Docker Container?

To start Docker container, you can use the docker start command followed by the container ID or name. For example:

docker start my-container

This command will start the container named “my-container”. You can also use the container ID instead of the name. If you haven’t created the container yet, you can use the ‘docker run’ command to create and start a container in one step. For example:                                                      docker run -it –name my-container my-image This command will create and start a new container named “my-container” based on the Docker image “my-image”. The “-it” flag enables interactive mode, so you can interact with the container’s command line. This is how you can start Docker container. Before, you start with Docker, it’s important to have a good understanding of Docker. Reading this blog will help you in getting started.

[Good Read: Docker Versus Kubernetes: Know The Difference!]

How is the Docker Run Command helpful?

After reading about how to start Docker, you’ll now need to know how is the Docker Run Command helpful. The docker run command inside container is one of the most important commands in the Docker CLI and is used to run Docker containers. When you run a Docker container, you are essentially running an instance of a Docker image. The docker run command allows you to specify various options and arguments to customize the behaviour of the container. Here are some of the ways the docker run command can help you:

  • Isolation: Docker containers provide a lightweight and isolated environment for applications to run in, which makes it easier to manage and deploy applications. When you run a container with the docker run command, you can specify various options and arguments to customize the environment and behaviour of the container.
  • Port Mapping: The docker run command allows you to map ports from the host system to the container, which is useful for exposing applications running inside the container to the network. For example, if you have a web application running inside a container and you want to expose it to the network, you can use the -p option to map a host port to the container port.
  • Environment Variables: The docker run command allows you to set environment variables inside the container. Environment variables are used to store configuration information and can be used by applications running inside the container. For example, you can set the DATABASE_URL environment variable to specify the location of a database used by your application.
  • Volumes: The docker run command allows you to mount host volumes inside the container, which is useful for sharing data between the host and the container. For example, you can use the -v option to mount a host directory inside the container, which allows your application to access files stored on the host.
  • Interactive Mode: The docker run command allows you to run a container in interactive mode, which is useful for debugging and troubleshooting. When you run a container in interactive mode with the -it option, you can interact with the container through the command line and run commands inside the container.

Overall, the docker run command is a powerful tool that allows you to run Docker containers and customize their behaviour. Whether you are developing, deploying, or managing applications, the docker run command can help you get the job done.

Docker Run: Your One-Stop Solution for Container Management

In this blog, we explored how to use the Docker run command, several Docker run command examples, how to start Docker container and numerous ways the docker run command can be used to simplify software development, testing, and deployment tasks, making the entire process faster, more efficient, and highly portable across different environments. Additionally, the docker run command can be used to manage the lifecycle of containers. You can start, stop, restart, or remove containers using the docker run command with the appropriate options.

Relation between Kubernetes and Docker run command:

Kubernetes uses the docker run command internally to start containers on worker nodes. When you create a Kubernetes deployment, it creates one or more replicas of your containerized application using the docker run command. However, Kubernetes goes beyond just running individual containers. It enables you to deploy containerized applications at scale, manage their resources, provide load balancing, and perform rolling updates or rollbacks. While docker run is used to manage individual containers, Kubernetes is used to manage containerized applications at a higher level of abstraction, making it easier to manage and scale applications running in production. Overall, both effective container management and seamless Kubernetes management are essential for realizing the benefits of containerization and ensuring the success of container-based applications. Additionally, to ease the complexity and intricacies of deploying Kubernetes, a Kubernetes management platform such as BuildPiper can help. Get in touch with our experts to discuss critical business scenarios or seek assistance for solving major Kubernetes management issues & challenges NOW! Watch our video tutorials for a quick & easy understanding of BuildPiper.

 

CONTACT US

 

 
 
                                                                       
                                                                             

 

  • LinkedIn
  • YouTube
  • GitHub
  • Medium
  • Twitter

 

 

 

Tags docker run commanddocker run command examplesdocker run command inside containerhow to start dockerstart docker containerstart with docker
Previous Post
All you need to know about YAML Files
Next Post
How Elasticsearch Works?

Leave a Comment Cancel reply

Recent Posts

  • Revolutionizing DevOps Transformation with BuildPiper
  • Accelerating Your DevOps Journey with BuildPiper
  • Balancing Shift Left and Shift Right in Your DevOps Strategy
  • 5 Best Practices for Implementing DevOps Security
  • Mastering Git Branch Deletion: A Step-by-Step Guide

Categories

  • Application Modernization 6
  • AWS 1
  • Canary 3
  • Cloud computing 5
  • cluster management 2
  • Container Orchestration 1
  • Containers 8
  • Continues Delivery 8
  • Continuous Deployment 7
  • Continuous Integration 9
  • Deck 2
  • DevOps 46
  • DevOps Monitoring 4
  • DevOps Platform 2
  • DevOps tools 2
  • DevOps Transformation 1
  • DevSecOps 8
  • Docker 3
  • Docker Alternatives 1
  • Docker containers vs images 1
  • Docker Hub alternatives 1
  • Docker image vs Container 1
  • Docker images vs containers 1
  • docker run command 1
  • docker versus kubernetes 1
  • Dockerfile 1
  • ECS 1
  • Elasticsearch 1
  • Git 1
  • Git Delete Branch 1
  • GitOps 2
  • Helm 3
  • Helm Charts 4
  • How does Elasticsearch works? 1
  • How to Create a Dockerfile 1
  • how to start docker 1
  • Hybrid cloud 2
  • Ingress 1
  • Istio 4
  • Istio Service Mesh 1
  • kubectl commands 1
  • Kubernetes 40
  • kubernetes challenges 1
  • Kubernetes Security 2
  • Low code platforms 1
  • Managed Kubernetes 6
  • Managed Microservices 5
  • MEME 7
  • Microservices 24
  • Service Mesh 3
  • Shift Left vs Shift Right 1
  • Sketchs 5
  • Yaml 1
  • Yaml File 1

Recent Comments

  • Ruchita Varma on How To Choose A Kubernetes Management Platform That Is Right For You?
  • Ruchita Varma on How To Choose A Kubernetes Management Platform That Is Right For You?
  • Ruchita Varma on How To Choose A Kubernetes Management Platform That Is Right For You?
  • Ruchita Varma on How To Choose A Kubernetes Management Platform That Is Right For You?
  • Ruchita Varma on How To Choose A Kubernetes Management Platform That Is Right For You?

Tags

application containerization application modenization blue-green deployments canary deployment Canary Deployments canary deployment strategy canary release deployment CI/CD ci cd pipeline cicd pipeline cluster management continuous delivery continuous deployment devops devsecops tools Helm Helm Chart Helm chart in Kubernetes Helm in Kubernetes hybrid cloud architecture istio service mesh K8s kubernetes kubernetes api Kubernetes challenges kubernetes cluster Kubernetes Dashboard kubernetes deployment kubernetes management kubernetes management tool kubernetes monitoring Kubernetes Security Kubernetes security challenges managed kubernetes Managed Microservices microservice architecture microservice orchestration tools microservices microservices application Microservices challenges Monitoring in DevOps monitoring microservices Monitoring tools in DevOps Service Mesh WHat is a Helm Chart?
Shape
Logo

Features

  • Microservices Delivery
  • Secure CI/CD Pipelines
  • Managed Security & Observability
  • Managed Kubernetes

Resources

  • Documentation
  • Release Notes
  • Workshop
  • eBooks and more...
  • Case Studies

Company

  • Blogs
  • Walk Through
  • Podcast & Shows
  • Contact Us

Contact Info

  • India, US
  • connect@buildpiper.io
Twitter
Linkedin
youtube
Github

© Copyright 2021. All Rights Reserved. Buildpiper is a product of Opstree Solutions (a subsidiary of TechPrimo Solutions Pvt. Ltd.)