How to Start with Docker

How to  Start with Docker
Techiio-author
Written by Nilima PaulFebruary 18, 2022
10 min read
Docker
3 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 3 VIEWS SHARE
Techiio-author
Nilima Paul

Technology Security Analyst

We will discuss How to Start with Docker.

Introduction to Docker Start:

The 'docker start' is a Docker order to begin at least one halted compartment. We can likewise utilize this holder to begin the compartment that we have made utilizing the 'docker make' order or the compartments that are in 'made' status because the 'docker make' order makes the compartment yet doesn't begin naturally. For instance, assuming we have made a Naninx compartment and uncovered port 80 remotely yet that holder will serve until it is begun utilizing the 'docker start' order. This order has likewise a couple of banners to get the intelligent control center, reestablish from the designated spot, append STDOUT/STDERR, and so forth

How does Start Command work in Docker:

The 'docker start' works similarly to different orders work in Docker. At the point when we run this order from the CLI with compartment name passed as a contention, Docker CLI settles on an API decision to the Docker daemon and daemon begins that holder assuming the compartment is in the halted state or the made state. We would not open be able to port, give it a name, append volumes, and so on while beginning the holder in if isn't designed while running or making that compartment. This order is essentially going to begin the holder, be that as it may, we can utilize a couple of banners to control not many things like interfacing with the compartment whenever it is begun, appending STDOUT/STDERR, and so on

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 1

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

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

Command 2

docker container stop my-Nginx

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 3

docker start my-Nginx

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 4

docker start <container_name1> <container_name2> <container_name3>

Or

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

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 the below command:

Command 1

docker create -p 80:80 –name my-nginx2 nginx: alpine

docker ps -f ‘status=created’

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

Command 2

docker start my-nginx2

curl http://localhost:80

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 1

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 2

docker create hello-world

docker start -a <container_ID or container_name>

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 Userspace) to work with Docker checkpoints. We can simply install CRIU using the below command:

Command 1

sudo apt-get install cream

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 2

sudo vi /etc/docker/daemon.json

sudo systemctl restart docker

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

Command 3

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'

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 4

docker logs checkpoint-cont

docker checkpoint create checkpoint-cont checkpoint-01

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 5

docker start --checkpoint checkpoint-01 checkpoint-cont

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.

Benefits of Docker Start:

  1. We can begin the halted or made holder utilizing the Docker Start without any problem.
  2. We can likewise begin any holder from the designated spot that we have made before utilizing the 'docker make designated spot'.
  3. We can likewise begin another holder with the designated spot of any unique compartment utilizing the '- designated spot dir'.

Conclusion:

This order is truly helpful in beginning compartments from designated spots, notwithstanding, the designated spot work is just accessible in the trial mode so we want to empower exploratory view before utilizing this capacity.

Docker
Docker Start
Docker secrets
DevOps
Docker file
3 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 3 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance