May 22, 2021 Docker From entry to practice
There are two ways to start a container, one is to create a new container based on the mirror and start it, and the other is to restart the container in the stop state.
Because Docker's containers are so lightweight, many times users delete and create containers at any time.
The command required is
docker run
For example, the following command outputs a "Hello World" and then terminates the container.
$ sudo docker run ubuntu:14.04 /bin/echo 'Hello world'
Hello world
This makes almost no difference to
/bin/echo 'hello world'
directly locally.
The following command starts a bash terminal that allows the user to interact.
$ sudo docker run -t -i ubuntu:14.04 /bin/bash
root@af8bae53bdd3:/#
Where the
-t
allows Docker to assign a pseudo-tty and bind to the container's standard input,
-i
the container's standard input open.
In interactive mode, users can enter commands through the terminals they create, for example
root@af8bae53bdd3:/# pwd
/
root@af8bae53bdd3:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
When
docker run
the standard operations that Docker runs in the background include:
You can
docker start
command to run a container that has been terminated directly.
The core of the container is the application that is executed, and the resources required are all necessary for the application to run. B
eyond that, there are no other resources.
You can view process information in
ps
top
or top.
root@ba267838cc1b:/# ps
PID TTY TIME CMD
1 ? 00:00:00 bash
11 ? 00:00:00 ps
As you can see, only the specified bash app is running in the container. This feature makes Docker extremely efficient with resources and is a true and lightweight virtualization.