The Ops Community ⚙️

Cover image for Docker Container manipulation Part-II
Akshay Rao
Akshay Rao

Posted on

Docker Container manipulation Part-II

Introduction
Hi, I am Akshay Rao this is the part II of container manipulations. I had written the blog on basic manipulation.
I will leave the link of the previous in the conclusion.
I have used Go app for demonstration purposes.
How to Restart a Container
Here there can be two situations

  1. Restating a stoped or killed container
  2. Rebooting a running container To restart a stopped or killed container we can use container start command docker container start “identifier”
docker container start akshay_rao
akshay_rao
akshayrao@HL00802 ~ % docker container ls -a
CONTAINER ID   IMAGE                                             COMMAND          CREATED        STATUS                    PORTS                    NAMES
6360b3c15f34   aksrao1998/first-go-project                       "/app/project"   28 hours ago   Up 14 seconds             0.0.0.0:8080->8080/tcp   akshay_rao
52fa8c04c200   aksrao1998/first-go-project                       "/app/project"   29 hours ago   Exited (2) 28 hours ago                            elated_colden
b2f071967c1a   aksrao1998/first-go-project                       "/app/project"   29 hours ago   Exited (2) 29 hours ago                            goofy_haslett
5db127b7f005   aksrao1998/first-go-repository:first-go-project   "/app/project"   29 hours ago   Exited (2) 29 hours ago                            nostalgic_margulis
eab55402a418   aksrao1998/first-go-repository:first-go-project   "/app/project"   29 hours ago   Exited (2) 29 hours ago                            blissful_sutherland
b0de1c496db1   aksrao1998/first-go-project                       "/app/project"   29 hours ago   Exited (2) 29 hours ago                            peaceful_moore
7c72eda7950c   aksrao1998/first-go-project                       "/app/project"   4 weeks ago    Exited (2) 4 weeks ago                             zealous_clarke
Enter fullscreen mode Exit fullscreen mode

Rebooting a container
docker conatiner restart “indentifier”

docker container restart akshay_rao
akshay_rao
Enter fullscreen mode Exit fullscreen mode

How to Create a Container Without Running
docker container create “image-name”

docker container create  -p 8080:8080 aksrao1998/first-go-project
6360b3c15f34b8dc605079cfd1c58f9e4ea9c900d4307bab5fafe766c4623451
Enter fullscreen mode Exit fullscreen mode

How to Remove Dangling Containers
Container rm command is used when un-necessary container are there.
docker container rm “container-identifier”
There is also option —rm for container run and container start commands which will remove the containers as soon as they are stopped.

docker container run —rm -p 8080:8080 —name remove_it  aksrao1998/first-go-project
Enter fullscreen mode Exit fullscreen mode

How to Run a Container in Interactive Mode
Sometimes we have to execute commands inside the container, -it option is used to get acccess to the STDERR.
Any interactive program inside a container can be interacted with using the -it option. This choice is actually the combination of two distinct choices.

You can send inputs to bash by connecting to the container's input stream using the -i or —interactive option.
By allocating a pseudo-tty, the -t or —tty option ensures that you receive good formatting and a native terminal-like experience.
Image 1
How to Work With Executable Images
The program running inside the container is isolated from the local host file system so to grant direct access used bind mounts.
By using a bind mount, you can create a two-way data connection between the contents of one directory (the source) on your local file system and another directory inside a container (destination). The source directory will benefit from any modifications made to the destination directory in this manner, and vice versa.
—volume or -v “”local file system directory absolute path:”container file system directory absolute path”:”read write access”
Conclusion
I have covered most of the container manipulation.
the last blog link:-https://dev.to/aksrao1998/docker-container-manipulation-part-i-1pbe
Thank you

Top comments (1)

Collapse
 
allay_19c35c0f7989c4f97cb profile image
Allay

In the intricate realm of Docker container manipulation Part-II, understanding the shanghai hair is like uncovering a crucial element in a strategic game. These links establish connections, much like the strategic moves in a game of chess. Mastering this aspect enhances the efficiency and interactivity of the containers, ensuring a seamless digital orchestration.