1

In Jenkins I installed Docker build step plugin.
In Jenkins, created job and in it, executed docker command selected build image. The image is created using the Dockerfile.The Dockerfile is :

FROM ubuntu:latest


#OS Update
RUN apt-get update
RUN apt-get -y install git git-core unzip python-pip make wget build-essential python-dev libpcre3 libpcre3-dev libssl-dev vim nano net-tools iputils-ping supervisor curl supervisor

WORKDIR /home/wipro
#Mongo Setup
RUN curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-3.0.2.tgz && tar -xzvf mongodb-linux-x86_64-3.0.2.tgz && cd mongodb-linux-x86_64-3.0.2/bin && cp * /usr/bin/
#RUN mongod --dbpath /home/azureuser/CI_service/data/ --logpath /home/azureuser/CI_service/log.txt --logappend --noprealloc --smallfiles --port 27017 --fork

#Node Setup
#RUN curl -O https://nodejs.org/dist/v0.12.7/node-v0.12.7.tar.gz && tar -xzvf node-v0.12.7.tar.gz && cd node-v0.12.7
#RUN cd /opt/node-v0.12.7 && ./configure && make && make install
#RUN cp /usr/local/bin/node /usr/bin/ && cp /usr/local/bin/npm /usr/bin/
RUN wget https://nodejs.org/dist/v0.12.7/node-v0.12.7-linux-x64.tar.gz
RUN cd /usr/local && sudo tar --strip-components 1 -xzf /home/wipro/node-v0.12.7-linux-x64.tar.gz
RUN npm install forever -g

#CI SERVICE
ADD prod /home//
ADD servicestart.sh /home/
RUN chmod +x /home/servicestart.sh
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["sh", "/home/servicestart.sh"]

EXPOSE 80
EXPOSE 27017

Then I tried to create the container and container is created.
When I tried to start the container, the container is not running.
When I checked with command:

docker ps -a

, it shows status as created only.
Its not in running or Exited state.

The output of docker ps -a is:

docker ps -a

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
8ac762c4dc84        d85c2d90be53        "sh /home/servi"   15 hours ago        Created                                 hungry_liskov
7d8864940515        d85c2d90be53        "sh /home/servi"   16 hours ago        Created                                 ciservice

How to start the container using jenkins?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
user2439278
  • 1,222
  • 7
  • 41
  • 75

1 Answers1

0

It depends on your container main command (ENTRPOINT + CMD)

A created state (for non data-volume container) means the main command failed to execute.
Try a docker logs <container_id> to see if there is any error message recorded.

CMD ["sh", "/home/servicestart.sh"] should be:

CMD ["/home/servicestart.sh"]

(The default ENTRYPOINT for Ubuntu should be ["sh", "-c"], so no need to repeat an "sh")

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • In jenkins, i had given command to start the container as sh /home/servicestart.sh when i checked the logs, getting error as "No such container" – user2439278 Feb 10 '16 at 05:19
  • @user2439278 check if you are using the right container id for your `docker logs` command: what `docker ps -a` returns? – VonC Feb 10 '16 at 05:37
  • @user2439278 OK. What `docker logs 8ac762c4dc84` return? – VonC Feb 10 '16 at 05:42
  • Error: No such container: 8ac762c4dc84 – user2439278 Feb 10 '16 at 05:43
  • @user2439278 strange, but possible considering it is its abbreviated ID. Try `docker logs hungry_liskov` – VonC Feb 10 '16 at 05:44
  • It retruns nothing :( – user2439278 Feb 10 '16 at 05:45
  • @user2439278 OK then. Try the CMD I mention in my answer to see if the logs are more complete. – VonC Feb 10 '16 at 05:46
  • If i run docker run command directly in terminal,i can able to view the logs and status shows Exited. But when i start through docker plugin in jenkins, im unable to view logs and status is in Created only. – user2439278 Feb 10 '16 at 06:00
  • any other jenkins plugin available to start the docker container? – user2439278 Feb 11 '16 at 04:58
  • @user2439278 Try a regular custom Jenkins job where you would type the `docker` commands in a build step, in order to try and reproduce what you are typing successfully in command line. Make sure `CMD` (in your Dockerfile) is a I mention in the answer though. – VonC Feb 11 '16 at 05:21