Please read the previous articles related to azure
From the above image , you can see the list of images complete details inside that
Now, i want to list out all the container details
Now, from the above screenshot you can compare the ids.
You can forcefully delete the container instead of stopping it. By using the below command
docker rm -f containerId or Name
Committing Changes to Docker
Running a Container
Running of containers is managed with the Docker run command. To run a container in an interactive mode, first launch the Docker container.
Syntax: sudo docker run –it centos /bin/bash
Now, let us exec the command using bash
docker exec -it test123 bash
From the above image you can see once you have runned the command, It has changed the root ip to the container id.
Type ls command to list the files inside it
Let me run the below command to create a directory inside thatroot@83059965016c:/# mkdir demo123
Let me go inside that directory and create a sample text and save with sample.txt name
root@83059965016c:/demo123# echo "This is my tes file">sample.txt
root@83059965016c:/demo123# ls
root@83059965016c:/demo123# exit
Now, if i click on exit i am going to come back again to root folder.
Now, i want to commit this changes
Still am changes are in the temp memory. That is not permanent. Now let us go back to AWS Account and check.
Now, we need to give read and write permissions to that file first. We can also install package as well.
Try to install apache2 by running the below command
apt install apache2 -y
Try to install git by running the below command
To check if the git is installed, use the below command
root@83059965016c:/# git -v
git version 2.39.2
We can also go inside the folder by using the below commands
root@83059965016c:/# ls/usr/share/
Finally exit the command n then use commit command
docker commit containerid or name
The above commit will be saved in the docker images.
if we check
Few more Commands
docker images -q
This command is used to return only the Image ID’s of the images.
docker inspect
This command is used see the details of an image or container.
Syntax
docker inspect imagename
docker history
With this command, you can see all the commands that were run with an image via a container.
docker history ImageID
docker stop
This command is used to stop a running container.
Syntax
docker stop ContainerID
docker rm
This command is used to delete a container.
Syntax
docker rm ContainerID
docker stats
This command is used to provide the statistics of a running container.
docker stats ContainerID
docker pause
This command is used to pause the processes in a running container.
docker pause ContainerID
docker unpause
This command is used to unpause the processes in a running container.
docker kill
This command is used to kill the processes in a running container.
docker kill ContainerID
Docker – Container Lifecycle
The following illustration explains the entire lifecycle of a Docker container.
Initially, the Docker container will be in the created state.
Then the Docker container goes into the running state when the Docker run command is used.
The Docker kill command is used to kill an existing Docker container.
The Docker pause command is used to pause an existing Docker container.
The Docker stop command is used to pause an existing Docker container.
The Docker run command is used to put a container back from a stopped state to a running state
docker container prune:
This is the command, which will delete all the exited containers.
What is difference between docker run and docker start?
Docker start command is used to start any stopped container. Docker run command is a combination of creating and start as it creates a new container and starts it immediately.
What is difference between docker attach and Docker exec?
This is basically the major difference between exec and attach. When you run an exec, it will basically spins up a new process inside the container whereas attach basically lets you attach to an existing process inside the container
Differences Between Docker Run and Docker Exec
The docker run command creates and starts a new container from an image, while the docker exec command interacts with an already running container
Example of Docker Attach