EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Docker Start

By Sarabjeet SinghSarabjeet Singh

Home » Software Development » Software Development Tutorials » Docker Tutorial » Docker Start

Docker Start

Introduction to Docker Start

The ‘docker start’ is a Docker command to start one or more stopped containers. We can also use this container to start the container that we have created using the ‘docker create’ command or the containers that are in ‘created’ status because the ‘docker create’ command creates the container but it does not start automatically. For example, if we have created an nginx container and exposed port 80 externally but that container is going to serve until it is started using the ‘docker start’ command. This command has also a few flags to get the interactive console, restore from the checkpoint, attach STDOUT/STDERR, etc.

Syntax:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

docker start [OPTIONS] CONTAINER [CONTAINER...]

Options: 

attach, -a: It is used to attach STDOUT/STDERR and forward signals.

checkpoint: It is used to restore the container from a specific checkpoint(experimental).

checkpoint-dir: We can use a custom checkpoint storage directory using this option.

detach-keys: Override the key sequence for detaching a container.

interactive, -i: It is used to attach the container’s STDIN.

help: It is used to get help for this command as shown below:

Popular Course in this category
Docker Training (4 Courses, 3 Projects)4 Online Courses | 3 Hands-on Projects | 11+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (4,831 ratings)
Course Price

View Course

Related Courses
Python Training Program (36 Courses, 13+ Projects)All in One Software Development Bundle (600+ Courses, 50+ projects)

docker start --help

Docker start 1

How Start Command works in Docker?

The ‘docker start’ works in the same way other commands work in Docker. When we run this command from the CLI with container name passed as an argument, Docker CLI makes an API call to the Docker daemon and daemon starts that container if the container is in the stopped state or in the created state. We can not expose port, give it a name, attach volumes, etc. when starting the container if it is not configured while running or creating that container. This command is simply going to start the container, however, we can use a few flags to control few things like connecting to the container once it is started, attaching STDOUT/STDERR, etc.

Example

Let’s understand more about this command with a few examples.

Example #1: Start One or Multiple Stopped Containers

Step 1: Let’s create an nginx container using the below command and access the default page using curl:

Command:

docker run -d -p 80:80 --name my-nginx nginx:alpine

curl http://localhost:80

Docker start 2

Step 2: Now, stop this the container using the ‘docker stop’ command and try to access localhost:

Command:

docker container stop my-nginx

curl http://localhost:80

Step 3: Let’s start the container again but this time using the ‘docker start’ command as we want to just start the stopped container, don’t want to create a new one.

Command:

docker start my-nginx

Docker start 3

In the above example, we can see that the default page is again accessible after starting the container.

Step 4: Let’s assume we have multiple containers in exited status that we want to start using a single command. We can do so as shown below:

Command:

docker start <container_name1> <container_name2> <container_name3>

Or

docker start $(docker ps -q -f “status=exited”)

Docker start 4

In the above snapshot, we can see that we have 3 stopped containers and all stopped containers have been successfully started.

Note: The command shown in the snapshot will only work if the container status is ‘exited’, we have to use the first command mentioned above if the container is in a different state or change the status in the command.

Example #2: Create a Container and then start it

Step 1: Let’s create a container using below command:

Command:

docker create -p 80:80 –name my-nginx2 nginx:alpine
docker ps -f ‘status=created’

curl http://locahost:80

Step 2: Now, start the container as below and try to access it again:

Command:

docker start my-nginx2

curl http://localhost:80

Docker start 5

Example #3: Attach the Container STDOUT/STDERR while starting it

Step 1:  Let’s create a ‘hello-world’ container as shown below and try to start it without any flag:

Command:

docker create hello-world

docker start <container_ID or container_name>

Step 2: We can see that there is no output on the screen after starting the container. Let’s create another container and start it with the ‘-a’ or ‘–attach’ flag:

Command:

docker create hello-world

docker start -a <container_ID or container_name>

scenario 3

In the above snapshot, we can see that we got the output on the STDOUT when we run the ‘docker start’ command with the ‘-a’ option. We also get the error if the container throws an error while starting it.

Example #4: Start Container with the Checkpoint

Step 1: First thing first, we need to install CRIU (Checkpoint/Restore in User space) to work with Docker checkpoints. We can simply install CRIU using the below command:

Command:

sudo apt-get install criu

Docker start 6

Step 2: Docker checkpoint only works in experimental mode for Docker, so let’s enable experimental mode by editing daemon.json file as shown below and restart the docker service:

Command:

sudo vi /etc/docker/daemon.json

sudo systemctl restart docker

scenario 4

scenario 4-1

Step 3: Let’s run a container using the ‘ubuntu’ Docker image using the below command:

Command:

docker run -d --name checkpoint-cont --security-opt seccomp:unconfined ubuntu  /bin/sh -c 'i=0; while true; do echo $i; i=$(expr $i + 1); sleep 5; done'

scenario 5

In the above example, we have created a container named ‘checkpoint-cont’ and it starts printing counting from 0 in every 5 secs that we can see in the logs and it is increasing.

Step 4: Let’s create a checkpoint named ‘checkpoint-01’ for this container using the below command:

Command:

docker logs checkpoint-cont

docker checkpoint create checkpoint-cont checkpoint-01

scenario 6

In the above snapshot, we can see that the container has already printed to 10 before creating a checkpoint.

Step 5: Finally, start the container using the ‘docker start’ command with the ‘–checkpoint’ option as shown below:

Command:

docker start --checkpoint checkpoint-01 checkpoint-cont

scenario 6-1

In the above snapshot, we can see that the counting has started where it left before creating the checkpoint.

Note: The container is stopped after creating a checkpoint.

Advantage

  1. We can start the stopped or created container using the Docker Start easily.
  2. We can also start any container from the checkpoint that we have created earlier using the ‘docker create checkpoint’.
  3. We can also start a new container with the checkpoint of any different container using the ‘—checkpoint—dir’.

Conclusion

This command is really useful in starting containers from checkpoints, however, the checkpoint function is only available in the experimental mode so we need to enable experimental view before using this function.

Recommended Articles

This is a guide to Docker Start. Here we also discuss the introduction and How Start Command works in Docker along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. Docker Privileged
  2. Docker Stack
  3. Docker Import
  4. Docker Systemd

Docker Training (4 Courses, 3 Projects)

4 Online Courses

3 Hands-on Projects

11+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Docker Tutorial
  • Docker
    • What is Docker in Linux
    • Docker Architecture
    • Install Docker
    • Advantages of Docker
    • Docker Commands
    • Docker Toolbox
    • Docker Storage Drivers
    • Docker Push
    • Docker run Command
    • Dockerfile
    • Docker Containers
    • Docker Container Linking
    • Docker Stop Container
    • Docker List Containers
    • Docker Registry
    • Docker Volume
    • Docker Images
    • Docker Export
    • Docker Import
    • Docker Systemd
    • Docker Stack
    • Docker Privileged
    • Docker Pull
    • Docker ENTRYPOINT
    • Docker Start
    • Docker system prune
    • Docker Hosts
    • Docker Logging
    • Docker Save
    • Docker Commands Cheat Sheet
  • Docker Swarm
    • What is Docker Swarm
    • Docker Swarm Architecture
  • Interview Questions
    • Docker Interview Questions

Related Courses

Docker Training Course

Python Training Course

Software Development Course Training

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Docker Training (4 Courses, 3 Projects) Learn More