I tried Docker Container manipulation Part-II

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

Introduction

I am Akshay Rao working in Annotation.Inc.I tried different container manipulations in this blog. 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

  • Restating a stoped or killed container.
  • 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

    Rebooting a container docker conatiner restart “indentifier”

    docker container restart akshay_rao
    akshay_rao

    How to Create a Container Without Running

    docker container create “image-name”

    docker container create  -p 8080:8080 aksrao1998/first-go-project
    6360b3c15f34b8dc605079cfd1c58f9e4ea9c900d4307bab5fafe766c4623451

    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

    How to Run a Container in Interactive Mode

    Sometimes we have to execute commands inside the container, -it option is used to get access 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.

    <li>You can send inputs to bash by connecting to the container's input stream using the -i or —interactive option.</li>
    <li>By allocating a pseudo-tty, the -t or —tty option ensures that you receive good formatting and a native terminal-like experience.</li>
    


    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.classmethod.jp/articles/i-tried-docker-container-manipulation-part-i/
    Thank you