Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

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

Posted on

     

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 containerTo restart a stopped or killed container we can use container start commanddocker container start “identifier”
docker container start akshay_raoakshay_raoakshayrao@HL00802 ~ % docker container ls -aCONTAINER ID   IMAGE                                             COMMAND          CREATED        STATUS                    PORTS                    NAMES6360b3c15f34   aksrao1998/first-go-project                       "/app/project"   28 hours ago   Up 14 seconds             0.0.0.0:8080->8080/tcp   akshay_rao52fa8c04c200   aksrao1998/first-go-project                       "/app/project"   29 hours ago   Exited (2) 28 hours ago                            elated_coldenb2f071967c1a   aksrao1998/first-go-project                       "/app/project"   29 hours ago   Exited (2) 29 hours ago                            goofy_haslett5db127b7f005   aksrao1998/first-go-repository:first-go-project   "/app/project"   29 hours ago   Exited (2) 29 hours ago                            nostalgic_marguliseab55402a418   aksrao1998/first-go-repository:first-go-project   "/app/project"   29 hours ago   Exited (2) 29 hours ago                            blissful_sutherlandb0de1c496db1   aksrao1998/first-go-project                       "/app/project"   29 hours ago   Exited (2) 29 hours ago                            peaceful_moore7c72eda7950c   aksrao1998/first-go-project                       "/app/project"   4 weeks ago    Exited (2) 4 weeks ago                             zealous_clarke
Enter fullscreen modeExit fullscreen mode

Rebooting a container
docker conatiner restart “indentifier”

docker container restart akshay_raoakshay_rao
Enter fullscreen modeExit fullscreen mode

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

docker container create  -p 8080:8080 aksrao1998/first-go-project6360b3c15f34b8dc605079cfd1c58f9e4ea9c900d4307bab5fafe766c4623451
Enter fullscreen modeExit 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 modeExit 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(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Devops Engineer
  • Location
    Tokyo,Japan
  • Joined

More fromAkshay Rao

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp