How to stop running node in docker

后端 未结 8 1985
广开言路
广开言路 2021-02-13 18:02

I have just installed dockers and installed node. I am able to run a basic express site. My issue now is I can\'t stop it. Control-C is not doing anything.

Temporarily w

8条回答
  •  一生所求
    2021-02-13 18:23

    As a part of solution, you can open your package.js and add 3 new commands/scripts :

    "scripts": {    
    
    "docker-build-and-run": "docker build -t image-dev-local . && docker run -p 3001:3001 --name container-dev-local image-dev-local",
    "docker-stop-and-clear": "(docker stop container-dev-local || true) && (docker rm container-dev-local || true)",
    "docker-run": "npm run docker-stop-and-clear && npm run docker-build-and-run"
    
    }
    

    and just simply run in the terminal :

    npm run docker-run
    

    to up your app on 3001 port in docker and have fun. Every next run will clear previous and build/run again.

    To stop and delete it, just run :

    npm run docker-stop-and-clear
    

提交回复
热议问题