skip to Main Content

I am running docker container Nginx, there are some errors in it,

  1. I cannot exec into the container because it is stopped, how can I exec into the stopped container.
  2. How to avoid the container stopping, if there exists an error in the container

Can someone help me by answering the above?

2

Answers


  1. It seems like the normal execution within your container causes it to stop. So what you need to do is, create a container with an overridden entrypoint (the procedure/command that is executed on container startup).

    A good place to start is by creating a shell instance where you can look around, and maybe even execute the same command manually for debugging purposes.

    So let’s say I have an image testimage:latest that on startup executes /bin/my_script.sh, which fails.

    I can then start a container with a shell instance

    $ docker run --entrypoint sh -it testimage:latest

    And within that container I can run the script, and check the output

    in_container$ /bin/my_script.sh

    Login or Signup to reply.
    1. I cannot exec into the container because it is stopped, how can I exec into the stopped container.

    No, you cannot exec onto a stopped container, you’d need to start the
    container up again before being able to exec onto it.

    1. How to avoid the container stopping, if there exists an error in the container

    As far as I am aware there is nothing to prevent a container stopping when there are errors, however I have found How to prevent a container from shutting down during an error? which might help you with what you need (please give them credit if it does work).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search