Aditya
Aditya

Reputation: 2536

container exited when docker run command

Dockerfile

FROM node:8.1.0
RUN http-server
RUN mkdir /app
COPY . /app
WORKDIR /app
RUN npm install
EXPOSE 2000

build the image successfully

docker run -d -p 8101:2000 --name xyz image

Container created and exited. When running docker logs container_id, nothing displays.

This is the process that I am following but unable to know the reason why my container is getting exited.

Upvotes: 0

Views: 537

Answers (3)

Dean Christian Armada
Dean Christian Armada

Reputation: 7384

You can try ping google.com as a CMD or ENTRYPOINT to enable continuous process of a container. There are scenarios that you really need to let that container still run even though it's process should end quickly. Example is when your cron is not yet ready for automated scraping

Upvotes: 0

Ayushya
Ayushya

Reputation: 10447

It is running default entrypoint, and when entrypoint has completed its work, the container exits.

If you want to edit the entrypoint, then either you specify your own or see what the default entrypoint is doing. You may find the dockerfile ans entrypoint details of your specific version in library/node

Upvotes: 1

yamenk
yamenk

Reputation: 51876

The Docker container runs as long as the process started with the CMD command inside the docker file is still running.

In your case, you didn't specify a CMD command in your docker file, and thus your container will exit immediately.

I can see that you intend to run an http-server. In that case, remove RUN http-server and replace it with CMD http-server in the end.

Upvotes: 0

Related Questions