mentongwu
mentongwu

Reputation: 473

Can not run docker container?

enter image description here

I use docker build -t iot . to build a image my Dockerfile is :

FROM centos
USER root
ADD jdk1.8.0_101.tar.gz /root
COPY  run.sh /etc
RUN chmod 755 /etc/run.sh
CMD "/etc/run.sh"

my run.sh is:

  #!/bin/bash
    echo "aaaa"

I use docker run -itd iot to run a container,but I find my container can not be run. enter image description here

what should I do?

Upvotes: 0

Views: 72

Answers (2)

Maroshii
Maroshii

Reputation: 4017

Your image builds and runs correctly. You just need to remove the d flag from run (for detached) or the docker command will exit immediately and run your container in the background. You can see that it actually exited with code zero according to the status column in docker ps -a.

You can corroborate this by running docker logs d63a (which is your container id). You should see aaaa.

Upvotes: 2

Yuankun
Yuankun

Reputation: 7793

Your description is inaccurate. When you docker run the container, it normally started, printed aaaa, and then exited.

So I guess what you would ask is "why my container cannot keep running, such as a daemon process". This is because you're executing a shell script which is actually a one-shot thing. Modify the CMD line in your Dockerfile to CMD "bash", your container will then not exit.

Upvotes: 0

Related Questions