Docker CMD to start Haproxy in Dockerfile - docker

Here is my CMD command in my Dockerfile for haproxy:
CMD ["/etc/init.d/haproxy"]
Now when I run the image the following happens:
...
Successfully built 2eb6549e0a22
root#server:/# docker run -d -p 80:80 -p 81:81 -p 443:443 -p 1988:1988 --name haproxy -h haproxy user/haproxy
09b510c4df712414d8855d3e0fb27b7e35d5c5c2f0f9b07f7f29c8efdb93e852
root#server:/# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
09b510c4df71 user/haproxy "/etc/init.d/haproxy" 5 seconds ago Exited (2) 4 seconds ago haproxy
As you can see it exits straight away. How do I keep it running?

Does your user/haproxy inherit from the haproxy container in the main docker repo? If so the command haproxy should be in the PATH and it includes a -f flag for running it in the foreground.
I usually specify the config file too, so my CMD looks like:
haproxy -d -f /usr/local/etc/haproxy/haproxy.cfg

Related

Nexus container exit(1) when run

I am trying to run nexus on EC2 ubuntu machine.
docker pull sonatype/nexus3
docker run -d -p 8081:8081 --name nexus sonatype/nexus3
running containers
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a0562da202f7 sonatype/nexus3 "sh -c ${SONATYPE_DI…" 7 seconds ago **Exited (1) 5 seconds ago nexus**
#
Please do let me know what is going wrong here.
I tried to reproduce the problem and I face the same as you tried, I resolve this by setting these variables.
docker run -it --rm -p 8081:8081 --name nexus -e INSTALL4J_ADD_VM_PARAMS="-Xms2g -Xmx2g -XX:MaxDirectMemorySize=3g -Djava.util.prefs.userRoot=/some-other-dir" sonatype/nexus3
Also, you can read the system requirement
Notes
Our system requirements should be taken into account when provisioning the Docker container.
There is an environment variable that is being used to pass JVM arguments to the startup script
INSTALL4J_ADD_VM_PARAMS, passed to the Install4J startup script. Defaults to -Xms2703m -Xmx2703m -XX:MaxDirectMemorySize=2703m -Djava.util.prefs.userRoot=${NEXUS_DATA}/javaprefs.

docker port command returning nothing

I am following the tutorial here.
In this, you launch a container like so :
docker run --name static-site -e AUTHOR="Your Name" -d -P dockersamples/static-site
e61d12292d69556eabe2a44c16cbd54486b2527e2ce4f95438e504afb7b02810
which I have done. Then it tells you to run the command :
docker port static-site
This is meant to return the ports the container is running on, right ?
It's returning nothing for me. How come ?
sudo docker ps -l shows it has been created.
Thanks a lot.
On MacOS, I have following results:
$ docker run --name static-site -e AUTHOR="Your Name" -d -P dockersamples/static-site
ac25e7cdd81725dfa157ff7027d1ed6beb3839c9457b9627728d700375e7a77f
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ac25e7cdd817 dockersamples/static-site "/bin/sh -c 'cd /usr…" 6 seconds ago Up 5 seconds 0.0.0.0:32774->80/tcp, 0.0.0.0:32773->443/tcp static-site
$ docker port static-site
443/tcp -> 0.0.0.0:32773
80/tcp -> 0.0.0.0:32774
Please inspect the result of the column 'ports' of the command docker ps on your machine where ports and the mapped ports are also displayed.

docker container is active but port is not displayed

I am building a docker image and running it will following command:
docker run --name myjenkins -u root -d -p 8080:8080 -p 50000:50000 -v jenkins-volume:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock --net=host vm31
docker container is up and running when i do docker ps output is :
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
22a92a3b7875 vm31 "/sbin/tini -- /usr/…" 4 seconds ago Up 3 seconds
why does not it show the port on which this container is running - so i can not reach jenkins on localhost:8080
You are using two conflicting things together:
--net=host
-p 8080:8080 -p 50000:50000
The first tells the container to use the network stack of the host, the second is the way to bind container ports with host ports. I believe you only want to use the second one.
try after removing option --net=host.

Container does not start if I map existing in container dir

I am trying to create a container with directory mapped to host directory.
docker run -d --name web1 -p 8080:80 -v /vagrant/web/config:/etc/nginx/conf.d nginx
But for some reason if I am specifying directory existing in the container - container is created (i get ID back) but it does not start.
if I run docker ps I do not see the container but if i run docker ps -a I see:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6b8bde856fdc nginx "nginx -g 'daemon off" 10 minutes ago Exited (1) 10 minutes ago web1
If i do the same but instead of existing /etc/nginx/conf.d dir I specify something else - it works.
There is no related records in log /var/log/upstart/docker.log
Additional info
Docker version 1.11.2, build b9f10c9
Ubuntu Trusty
What is the content of /vagrant/web/config in the host ?
The problem may be an error in one of your nginx configuration files that prevents nginx from starting. And if nginx doesn't start, the container stops from running.
Run another container with the same settings and bash as entrypoint. Afterwards manually start the command from the original container and look for the error:
$ docker run -it --entrypoint=/bin/bash --name web2 -p 8080:80 -v /vagrant/web/config:/etc/nginx/conf.d nginx
root#7553b294969f:/# nginx -g 'daemon-off'
# this is just an example with a badly formatted default.conf file
2016/07/04 08:14:15 [emerg] 10#10: unexpected end of parameter, expecting ";" in command line
nginx: [emerg] unexpected end of parameter, expecting ";" in command line

CKAN Docker container not running

I am running the example installation using docker container from the CKAN site. A clean run, that downloads fresh (no local images) gives no errors
docker run -d --name db ckan/postgresql
docker run -d --name solr ckan/solr
docker run -d -p 80:80 --link db:db --link solr:solr ckan/ckan
but then a "docker ps" does not have the ckan image running ...
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90c6e6a77b0a ckan/solr:latest "java -jar start.jar 15 minutes ago Up 15 minutes 8983/tcp solr
53f9a9f5c145 ckan/postgresql:latest "/usr/local/bin/run" 20 minutes ago Up 20 minutes 5432/tcp db
Where would errors show?
docker ps only lists running containers. You have to pass in the -a option in order to list all containers you have run
docker ps -a
Find the right container and run the following command to see any error messages it may have reported before shutting down
docker logs <container_id>
As at March 6 2015 described at https://github.com/ckan/ckan/issues/2255
ensure that you have killed off any solr containers still running using
docker rm <idnumber>
then use the more recent schema config
wget https://github.com/ckan/ckan/blob/master/ckan/config/solr/schema.xml
docker run -d --name solr -v `pwd`/schema.xml:/opt/solr/example/solr/ckan/conf/schema.xml ckan/solr
then repeat the original failing step:
docker run -d -p 80:80 --link db:db --link solr:solr ckan/ckan
-- EDIT -- This looks like it works but it introduces other problems.
Am going to experiment with suggestion to use https://github.com/datacats/datacats

Resources