Mosquitto not Starting in Docker Container - docker

I am building a Docker container from an Ubuntu image using Dockerfile. I would like the container to use the mosquitto broker.
In my dockerfile, I have this:
FROM ubuntu:latest
RUN apt-get -y update && apt-get -y upgrade
RUN apt-get install -y mosquitto
CMD ["mosquitto"]
I would expect the mosquitto service to start when I run the image as a container. I tried the -d option with the mosquitto CMD command in dockerfile. However, when I go to top or ps, I do not see mosquitto as a running process. When I, from within the container shell, type mosquitto -d, and subsequently go to top, I see mosquitto started . I also trid systemctl enable mosquitto followed by systemctl restart mosquitto.
Here is my Dockerfile currently:
FROM ubuntu:latest
RUN apt-get -y update && apt-get -y upgrade
RUN apt-get install -y mosquitto
CMD ["mosquitto", "-d"]
Which I then build the image from this and run it as a container.
I would expect the mosquitto broker to just start when the container does, but it does not. I am not sure why this is, based on the Docker documentation.

Related

Jenkins not starting in docker (Dockerfile included)

I am attempting to build a simple app with Jenkins in a docker container. I have the following Dockerfile:
FROM ubuntu:trusty
# Install dependencies for Flask app.
RUN sudo apt-get update
RUN sudo apt-get install -y vim
RUN sudo apt-get install -y curl
RUN sudo apt-get install -y python3-pip
RUN pip3 install flask
# Install dependencies for Jenkins (Java).
# Install Java 1.8.
RUN sudo apt-get install -y python-software-properties debconf-utils
RUN sudo apt-get install -y software-properties-common
RUN sudo add-apt-repository -y ppa:webupd8team/java
RUN sudo apt-get update
RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | sudo debconf-set-selections
RUN sudo apt-get install -y oracle-java8-installer
# Install, start Jenkins.
RUN sudo apt-get install -y wget
RUN wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | apt-key add -
RUN echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list
RUN sudo apt-get update
RUN sudo apt-get install -y jenkins
RUN sudo /etc/init.d/jenkins start
COPY ./app /app
CMD ["python3","/app/main.py"]
I run this container with the following:
docker build -t jenkins_test .
docker run --name jenkins_test_container -tid -p 5000:5000 -p 8080:8080 jenkins_test:latest
I am able to start flask and install Jenkins, however, when running, Jenkins is not running. curl localhost:8080 is not successful.
In the log output, I am able to see:
Correct java version found
* Starting Jenkins Automation Server jenkins [ OK ]
However, it's still not running.
I can ssh into the container and manually run sudo /etc/init.d/jenkins start to start it, but I want it to start on docker run or docker build.
I have also tried putting sudo /etc/init.d/jenkins start in the CMD portion of the Docker file:
CMD python3 /app/main.py; sudo /etc/init.d/jenkins start
With this, I am able to curl Flask, but still not Jenkins.
How can I get Jenkins to start automatically?
You have some points that you need to be aware of:
No need to use sudo as the default user is root already.
In order to run multiple service in the same container you need to use any kind of service manager like Supervisord. Jenkins is not running because the CMD is the main entry point for your container so only flask should be running. Check the following link in order to know how to start multiple service in docker.
RUN will be executed only during the build process unlike CMD which will be executed each time you start a container from that image.
Combine all the RUN lines together as possible in order to minimize the build layers which lead to a smaller docker image.
Regarding the usage of this:
CMD python3 /app/main.py; sudo /etc/init.d/jenkins start
It does not work for you because this command python3 /app/main.py is not running as a background process so this command sudo /etc/init.d/jenkins start wont run until the previous command is done.
I was only able to get this to work by starting Jenkins in the CMD portion, but needed to start Jenkins before Flask since Flask would continuously run and the next command would never execute:
Did not work:
CMD python3 /app/main.py; sudo /etc/init.d/jenkins start
This did work:
CMD sudo /etc/init.d/jenkins start; python3 /app/main.py
EDIT:
I believe putting it in the RUN portion would not work because container would build but not save the any running services. I'm not sure if containers can be saved and loaded with running processes like that but I might be wrong. Would appreciate clarification if so.
It seems like a thing that should be in RUN so if anyone knows why that didn't work or some best practices, would also appreciate the info.

I am trying to install gitlab omnibus packages on a ubuntu container

I lunched a container with
docker container run -it ubunutu
and run some commands :
apt-get update && apt-get upgrade -y
apt-get install curl openssh-server ca-certificates
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | bash
apt-get install gitlab-ce
until now it was all fine, but when I run gitlabctl reconfigure, It start and always stops in this step of installation ruby_block[supervise_redis_sleep] action run
Is there any solution to this problem??
I am using the latest version of ubuntu image, I also tried debian image. But all of them stop at that step!!
This is when I run apt-get install gitlab-ce , it was fine
but now when I run gitlab-ctl reconfigure , it stops always here
ruby_block[supervise_redis_sleep] action run

Use rabbitmq in Ubuntu 16.04 inside Docker

I am new to Docker. I want to create an image in Docker which to run a microservice that needs RabbitMQ and Redis. For Redis, I include redis in the line RUN apt-get install -y python python-pip libsasl2-dev libmysqlclient-dev redis-server wget inside Dockerfile. To install RabbitMQ, I use
RUN apt-get update
RUN apt-get -y -q --allow-unauthenticated install rabbitmq-server
RUN /usr/sbin/rabbitmq-plugins enable rabbitmq_management
RUN echo "[{rabbit, [{loopback_users, []}]}]." >
/etc/rabbitmq/rabbitmq.config
# Port to expose
EXPOSE 9060 5672 15672
However, the rabbitmq server is not running in default which will prompt error when I run the built image. I have a line ENTRYPOINT ["/docker-entrypoint.sh"] to run my microservice. How can I run the rabbitMQ service from Dockerfile?

Build and run container but there is no container

I have a dockerfile look like this
FROM ubuntu
MAINTAINER abc <abc.yur#gmail.com>
RUN apt-get update
RUN apt-get install nano
RUN apt-get install -y software-properties-common python-software-properties
RUN add-apt-repository ppa:longsleep/golang-backports
RUN apt-get update
RUN apt-get -y install golang-go git
RUN mkdir /work
ENV GOPATH=/work
RUN go get github.com/abc/golang
RUN go build github.com/abc/golang
CMD /golang -addr $ADDR -workers $WORKERS
So I want to build and run container but after the building (docker build .) I can not run this container. So when I am running docker ps -a or docker ps there is not container to run
docker build .
This creates the image and not a container. You need to use
docker images
To get the list of images.
docker ps will show when you run a container using something like below
docker run -d <image>

Docker container with Centos as base image is not running

I had created the Docker container for RabbitMQ using the Following Docker File, But not able to run the Container, It's automatically stops.
Docker File
FROM centos:centos7
RUN yum -y update
RUN yum -y install wget
RUN wget https://www.rabbitmq.com/releases/erlang/erlang-18.2-1.el6.x86_64.rpm
RUN yum -y install erlang-18.2-1.el6.x86_64.rpm
RUN wget https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.9/rabbitmq-server-3.6.9-1.el7.noarch.rpm
RUN yum -y install rabbitmq-server-3.6.9-1.el7.noarch.rpm
EXPOSE 15672
EXPOSE 5672
RUN rabbitmq-plugins enable rabbitmq_management
CMD /usr/sbin/rabbitmq-server -detached
Docker build Command
docker build -t rabbit .
Docker run command
docker run -d -p 15672:15672 rabbit
Container starts but's its exit's after a second
Thanks in advance

Resources