DEV Community

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

Posted on

3 1

I tried 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

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more