简体   繁体   English

Docker 容器在创建命令后停止

[英]Docker container stops after create command

I am trying to create a shell script that builds an image and then runs the container and executes commands that I pass to it, such as npm install, etc.我正在尝试创建一个 shell 脚本来构建映像,然后运行容器并执行我传递给它的命令,例如 npm 安装等。

At the moment, I have目前,我有

#!/bin/bash

docker container create -it --name testt <image_name>
docker container start testt
winpty docker container exec -it testt bash


read -rsp $'Press any key to continue...\n' -n1 key

And the first create command executes, but when I try to start it, it says the container is not running.第一个创建命令执行,但是当我尝试启动它时,它说容器没有运行。

edit to add Dockerfile:编辑添加 Dockerfile:

FROM node:8.16.2-alpine 

RUN apk add --no-cache --upgrade bash

WORKDIR /home/build

COPY . .

If you want to run your image you need to use docker run and not docker start如果要运行图像,则需要使用 docker run 而不是 docker start

docker run -d -it <image name>

The -d will keep it running in the background once you exit the container -d 将在您退出容器后使其在后台运行

Edit From the terminal try building the image with the following code snippet从终端编辑尝试使用以下代码片段构建图像

docker build -t <imageName>:<tag>

Then try running the image with然后尝试运行图像

docker run -d -it <imageName>:<tag>

Next run下一次运行

docker ps -a

Check if the container is still running检查容器是否仍在运行

If it is still running enter the container like so如果它仍在运行,请像这样进入容器

docker exec -it <container name> /bin/bash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM