Docker Tutorial 3

Serdar Arslan
4 min readJan 19, 2023

--

Hello friends, welcome to the third part of our Docker Training article, in this section we will talk about container life processes and Docker Volume.

Containers are normally named automatically, friends, and these names are a combination of two random words, the first part is an adjective, the second part is the names of well-known people in the IT world, but we can also name them while creating. We can use the :name option to do this.

As we saw above, we created a container named serdararslan from the hello-world image.
We use the stop command to stop the containers we have created.

Here, after the stop command, we write the id value of the container we want to stop, even if we do not write all of this value, docker understands this and performs the stopping process.
In Docker, we can list the containers by using the ps and ps –a commands, which do the same with the ls and ls –a command that we have explained before.

We can delete multiple containers at once in Docker.
We can use docker container rm id1,id2,id3…..
The important thing here is that we cannot delete running containers directly, for this we need to stop the container first.
If we want to force delete a running container without stopping it:
We use the command “docker container rm –f id”.

Apart from these commands, here are some commands we use when working with docker:
We can run it in detect mode with the -d command (in the background)

If we launch a container in detect mode, we will run it in the background, so we can easily do our other operations from the docker CLI.

The *sh command means connect to the shell of this container.
We use it to connect to the container interactively with the it command. which allows us to use a data set or enter data

“docker container exec –it containerName sh”
It means interactively connect to the container with the above command and set up the terminal connection to run it.
In Docker, we can use the ls –l command to see the files in the container.

  • We can use the “docker kill containerName” command to kill the container.
    If we want to delete all containers that are not running on the system at once, we can use the prune command.

DOCKER VOLUME

Since containers in Docker are created in seconds and processed quickly, we prefer to delete and open a new container instead of using the same container for changes we will make while working with containers.

In such cases, there is a need for a container-independent structure that keeps data in order for our system to work and not lose data. At this point, the volume structure helps us.
Units can run on both a Windows machine and a Linux machine.
Volumes can be shared across multiple containers,
Just like with containers, we can use create to create volumes and ls to list volumes.

To delete, we use the rm command, just like containers.
With the Inspect feature, we can see the details of the volume we have created.

In addition, there is no limitation in the Volume structure, so we can connect a volume to more than one container.

--

--