Solution Resort

Learn, try and share…

Category: Docker

Python CMD app like a CRON job in Docker

This Github repository is a boilerplate of a simple Python script called repeatably in a Docker container.

Recently I’ve deployed one of my home projects to ECS (AWS Elastic Container Service) using this approach and it worked seamlessly for over 3 weeks so I decided it’s time to share it. My use case was I needed to fetch some data every minute from a third party API and then send the data over to Kinesis. Google Functions combined with Google AppEngine is obviously one of the approaches ( but I think this approach using Docker is probably equally straightforward or even simpler.

The idea is very simple and it’s basically calling a Python script using a fixed interval in a bash script. The reason for using a shell script is that it’s not limited to just Python, but anything can be executed from the command line.

OK, give it a try and let me know how you get on with it 🙂

Install Docker on Ubuntu 16.04

Feel free to grab:

MySQL in Docker without losing data after rebuild

When it comes down to running database services or anything that has states in it with docker containers, the first question is often “how about my data” after the container is destroyed or rebuilt?

The simple answer is you can use Docker Data Volumes.

After reading a few articles as well as trying it out myself, the easiest and cleanest way I found is to create a Data Container with a volume first, and then tell your MySQL container to use the data volume on that container.

This can be simply done with two commands,

# creates the volume container and mount /var/lib/mysql

docker create -v /var/lib/mysql --name mysql_data_store busybox /bin/true
# start the mysql container and tell it to use the created volume on the mysql_data_store container. Do not use the -d option if you are running it with CoreOS

docker run --volumes-from mysql_data_store --name mysql -e MYSQL_ROOT_PASSWORD=<your long password> -d mysql:latest

Now if you kill and remove the MySQL container and recreate it by mounting the same data volume again, all the data you have won’t be lost because the data volume has not been destroyed. The MYSQL_ROOT_PASSWORD option will be redundant the second time you run the container as the MySQL service has already been installed.

I’ve not tried this on production yet but will do soon on some hobby projects.

More reading:

Run Docker and Docker Compose in a Vagrant box

Created recently which provisions a Vagrant VM (Ubuntu trusty) with everything necessary installed to run docker & docker compose.

The main reason I created this is because it gives you an isolated environment to run things without going through the hassle of installing docker & docker compose which can be quite annoying if you are running i.e. Mac OSX and wanted to use your own docker hub repo.

All you need to do is to install Vagrant which could be much easier than installing docker & docker compose depending on the OS you use.

Simply check it out and follow the instructions.

Powered by WordPress & Theme by Anders Norén