简体   繁体   中英

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.

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:

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 -d -it <image name>

The -d will keep it running in the background once you exit the container

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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