Posts tagged with ‘docker’
Order of containers in Docker Compose
kinow @ Mar 14, 2017 21:22:03Tweet
In Docker Compose you are able to control the startup order of the containers via the depends_on statement. This is documented in Controlling startup order in Compose.
If you have a simple setup, with Tomcat and Postgres, sometimes Postgres will start first, but Compose will initialize Tomcat before Postgres has fully booted. When that happens, you may receive 401, 404, or other application errors.
You can fix it by combining depends_on with a healthcheck. For example:
# File: docker-compose.yml version: '2.1' services: db: container_name: twpg build: context: . dockerfile: Dockerfile.postgres restart: always ports: - "5432:5432" healthcheck: test: "pg_isready -h localhost -p 5432 -q -U postgres" interval: 10s timeout: 5s retries: 5 web: container_name: twtc build: context: . dockerfile: Dockerfile.tomcat restart: always depends_on: db: condition: service_healthy links: - db ports: - "80:8080"
In the example docker-compose.yml, there are two containers, db and web. web is running a Tomcat, and db is running Postgres. Web depends on db (see depends_on), and uses a condition service_healthy. Which indicates it depends that that container is healthy.
The healthcheck entry under the db container settings define how to check whether Postgres is running or not. In this case, we are using pg_isready, which is available in the vanilla Postgres 9 container.
It will try 5 times, with a 10 seconds interval, and will time out after 5 seconds. You may have to tune these parameters for your application.
This code snippet is from a pull request submitted to Foxoncz/docker-thingworx.
♥ Open Source
Trying SaltStack with Docker
kinow @ Apr 17, 2016 22:06:03Tweet
Some weeks ago I started learning SaltStack for a project at work. But I couldn’t find a good Docker image for that and I had to ask the Ops team for some VM’s. We are having a rainy weekend in Auckland, so I decided to have another look at the Jenkins SaltStack Plug-in.
But now since I was at home, I couldn’t use the VM’s that I had access to at work. So decided to look again at Docker or Vagrant images. After playing with a few images, I found bbinet/salt-master. It not only sets up a master, but also provides an easy way to enable the cherrypy API (necessary for the Jenkins plug-in).
This post describes the steps that I took to have a running Salt Master with the API enabled. First you need to create some directories and files to use with the image.
shell$ mkdir ~/master && cd ~/master shell$ mkdir -p config/master.d/ shell$ vim config/master.d/api.conf
The api.conf contains the SaltStack API configuration. You can change port, user and other settings if necessary. Just remember to add a credential in Jenkins for the plug-in.
# File: api.conf external_auth: pam: saltapiuser: - .* - '@runner' - '@wheel' - '@jobs' rest_cherrypy: port: 8000 host: 0.0.0.0 disable_ssl: True static: /opt/molten static_path: /assets app: /opt/molten/index.html app_path: /molten
The image also conveniently provides a script that is executed before the entry point (if provided). So we can also create a user for the API automatically when the image is created.
shell$ vim config/before-exec.sh
#!/bin/bash # File: before-exec.sh useradd saltapiuser echo -e "nosecret\nnosecret\n" | passwd saltapiuser exit 0
Also make the script executable.
chmod +x config/before-exec.sh
And finally start the container.
docker run --name salt-master -v $PWD/config:/config \ -p 4505:4505 -p 4506:4506 -p 443:443 -p 8000:8000 \ bbinet/salt-master
Once the container is running, you can go to http://localhost:8000 and log in as saltapiuser:nosecret, and also configure your plug-in in Jenkins.
Deploying WAR files to Tomcat with Jenkins
kinow @ Mar 20, 2016 15:29:03Tweet
Table of Contents
- Deploying with custom scripts
- Deploying with a build tool
- Deploying with a build server
- Final thoughts
A co-worker asked me this week about how to deploy a WAR file to Tomcat with Jenkins. In my team we are currently maintaining and deploying about 10 Java web systems, but we have no consistent way of deploying the applications to Tomcat yet. In the past I used Ant, Maven, Cargo, Grunt, and Jenkins, so I decided to write this short post to show a few different ways it can be achieved, à la Perl’s TMTOWTDI motto.
At first you may be tempted to write your own script to deploy to Tomcat with some Shell, Perl, Python or Java. But I think I would choose this option only because either I needed some feature that is not available in the other options, or in order to call other tasks or debug some problem.
$ docker run -d -p 8888:8080 jeanblanchard/tomcat:8 $ git clone https://github.com/spring-projects/spring-petclinic.git && cd spring-petclinic && mvn package $ curl --upload-file target/petclinic.war "http://admin:admin@localhost:8888/manager/text/deploy?path=/spring-petclinic&update=true" OK - Deployed application at context path /spring-petclinic
( Read more … )