Showing posts with label Docker. Show all posts
Showing posts with label Docker. Show all posts

Thursday, May 4, 2017

Open Source: Dockerfile for MariaDB on CentOS

Previously I need to have a version of mariadb running on Windows without any installation, during the process i developed two solutions:
  • a standalone mariadb in java using embedded mariadbs server 
  • a docker image which that automates the configuration of mariadb on centos container
The dockerfile and associated files which build and configure mariadb for centos is now released as an open-source project in github:


The features and usage of this docker image is described below:



Docker Project logo Mariadb Project logo

Features

  • The docker image is built from centos/systemd
  • Allow user to create a database in the mariadb if the database is not created when docker container is started
  • Allow user to configure the password for the 'root' account of mariadb
  • Allow user to user to ssh into the container to start or stop the mariadb if needed
  • Allow user to configure the mariadb such as default encoding, maximum connections, max packat allowed

Usage

Git clone the project to your local computer:
git clone https://github.com/chen0040/dockerfile-centos-mariadb.git

Build the mariadb docker image

Run the following command from the root folder of the project to build your own docker image:
docker build -t xschen/mariadb .
You can optionally save the image by running the following command:
docker save -o xschen-mariadb.img xschen/mariadb

Create and start the docker container

docker run -it --name=xschen-mariadb -u 0  -d -p 3306:3306 xschen/mariadb
Now you should be able to connect to the mariadb from your local computer at the port 3306,
an example of the data source url will be:
jdbc:mysql://127.0.0.1:3306/my_database?useSSL=false&useUnicode=yes&characterEncoding=UTF-8
Note that 127.0.0.1 may need to be replaced with the ip of your docker machine VM (depends how you set up your docker machine)

Start and stop the mariadb in the container

To start or stop the mariadb in the container, make sure that the container is running, then run the following command from your local computer:
docker exec -it xschen-mariadb /bin/bash
Once in the container, run the following command to start or stop the mariadb:
$ cd /home/xschen
$ sudo ./start.sh
$ cd /home/xschen
$ sudo ./stop.sh

Tuesday, October 13, 2015

Redis: Running redis server in docker container and access it from Windows host

Start the boot2docker on Windows host, run the following commands to create a container instance:

> docker run -i -t -p 6379:6379 --name=redis ubuntu bash

Note that the "-p 6379:6379" expose the port 6379 (which is the port on which redis server run by default) of the docker container as the port of the docker vm, so that it can be accessed from the Windows host. In the "redis" container, run the following command to install the necessary tools for building redis:

> sudo apt-get update
> sudo apt-get upgrade
> sudo apt-get install build-essential
> sudo apt-get install tk8.5 tcl8.5
> sudo apt-get install wget

In the "redis" container, run the following command to download and build the redis

> cd /opt
> wget http://download.redis.io/redis-stable.tar.gz
> tar xvzf redis-stable.tar.gz
> cd redis-stable
> make distclean
> make test

In the "redis" container, run the following command to start running the redis server:
> cd /opt/redis-stable/src
> ./redis-server

Open a console windows on the Windows host and type the following command to find out the boot2docker ip address:

> boot2docker ip

which should return something like 192.168.59.103  (Note that the address 192.169.59.103 is the ip address of the docker vm, which by default the docker container is mapped to)

Now start a redis client from the Windows console windows (if you have not downloaded the redis client binary, can download it from https://github.com/ServiceStack/redis-windows) by entering the following command line in the console of the Windows host:

> cd [your-redis-windows-binary-directory]
> redis-cli.exe -h 192.168.59.103

That's it. This is the link to some C# demo code (using the ServiceStack.Redis library via nuget) which connect to the redis server running in the docker container:

https://dl.dropboxusercontent.com/u/113201788/Redis/RedisDemoCSharp.zip


Wednesday, June 17, 2015

docker on centos 7: are you trying to connect to a tls-enabled daemon without tls

After install docker on centos 7 and try to run a simple docker command such as "sudo docker images", it failes with this error message:

"Get http:///var/run/docker.sock/v1.18/images/json: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS?"

After some trial and error, it appears that centos actually does not launch docker service (not sure something to do with firewall in centos 7), anyway, running the "sudo service docker start" fix the problem.

Install and start docker on centos 7

Nice post on how to install and start docker on centos 7:

Link: http://www.liquidweb.com/kb/how-to-install-docker-on-centos-7/

Sunday, April 26, 2015

Setup the event log folder as a share volume to docker container using boot2docker on Windows 7

To share the event log folder with a docker container, run:

> sudo docker -i -t --name=myContainer -v /c/Windows/Sysnative/winevt/Logs:/var/winevt ubuntu:14.04 /bin/bash

The "-v" command maps the "c:Windows/System32/winevt/Logs" to "/var/winevt" in the ubuntu container as a shared volume. Note that the default path such as "C:Windows\System32\winevt\Logs" will not work, has to be specified as "/c/Windows/Sysnative/winevt/Logs"

sh: docker: command not found

Today I was stricken by some strange behaviors when working with Docker on Windows 7. Firstly , the docker fails to initialize, either stuck at initialization or starting. This I was able to solve by manual stop the virtual box headless process in the process manager, and then restart the boot2docker.

However, subsequently, i encountered a weird message after i was able to launch and login to boot2docker. That is, whenever i tried any docker command, the message said:

sh: docker: command not found

The message in the CLI indicates the docker should be usable. I tried several methods including delete the docker vm and restart boot2docker, but to no effect. I went on goolging but there seems to be no mentioning of solution, the docker site mentions it may has something to do with docker installation being incorrect. However, the docker i am using has been running all the time without any problem until today.

The cause of the problem finally surfaced when i run the following command:

> echo $PATH

The printed out path indicates that docker and git are not found on the path, although i have added them much earlier during docker installation. Some closer examination showed that the entire path variable defined for user is not included in %PATH%.

After some investigation, it turned out that i installed the Visual SVN server and TortoiseSVN for some testing today, and their directory path are added to the system path variable during installation. this cause the system path variable to become too long. As a result, the Windows OS silently drop the user path variable, only keeping the system path variable in the %PATH%.

The solution after knowing this is simple, i uninstall some application no long in use and remove their directory from the system path variable so that my system path variable won't be too long. After this, restart the boot2docker, and the problem disappear.