jiboulex
jiboulex

Reputation: 3031

Is it possible to access the entry command bash on a running docker container?

I have a node docker container on which i'm running a dev server.

In my docker-compose.yml file, the entry command is :

...
command: start-dev-server
...

Where start-dev-server points to a script that starts the server after a vendor install :

// /usr/local/bin/start-dev-server
#!/usr/bin/env bash

# install node modules if missing
npm i
# start the dev server
npm run start

So when I start my container, the server will also start.

I know that I can access my container in bash via the following command :

docker exec -it my-container bash

But there I can't stop or restart my server. Is there a way to access the ssh with the started command ? (to see the server logs for example, or to stop & restart it).

Maybe I take it by the wrong path here because the entry command isn't supposed to be stopped ? So in this case, would anyone has a solution that could allow me to start my server & control it in a more flexible way ?

Upvotes: 1

Views: 102

Answers (1)

charli
charli

Reputation: 1778

The best practices says that you should see the container as your server. If you want to stop it, stop the container (docker stop my-container), if you want to restart it, restart the container (docker restart my-container). Your server should log to stdout, so you can see the logs using docker logs -f my-container. So, you're right, the command isn't supposed to be stopped, as it will stop the container.

Upvotes: 2

Related Questions