04/15/2015: Running MySQL on Docker
This entry doesn't reveal any hidden secrets just the simple steps to start using MySQL on Docker.
* Install docker
* Install docker-compose
* mkdir firstdb
* cd firstdb
* vi docker-compose.yml
mysql:
image: mysql:latest
environment:
MYSQL_DATABASE: sample
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
MYSQL_ROOT_PASSWORD: supersecret
* docker-compose up
* docker-compose ps
Name Command State Ports
-----------------------------------------------------------------
firstdb_mysql_1 /entrypoint.sh mysqld Up 3306/tcp
* Use a one-shot Docker instance to display environment variables. Notice
the variables that start with MYSQL? Your programs can use these variables
to make the database connection.
docker run --link=firstdb_mysql_1:mysql ubuntu env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=abfc8d50633b
MYSQL_PORT=tcp://172.17.0.23:3306
MYSQL_PORT_3306_TCP=tcp://172.17.0.23:3306
MYSQL_PORT_3306_TCP_ADDR=172.17.0.23
MYSQL_PORT_3306_TCP_PORT=3306
MYSQL_PORT_3306_TCP_PROTO=tcp
MYSQL_NAME=/nostalgic_rosalind/mysqldb
MYSQL_ENV_MYSQL_PASSWORD=mysql
MYSQL_ENV_MYSQL_ROOT_PASSWORD=supersecret
MYSQL_ENV_MYSQL_USER=mysql
MYSQL_ENV_MYSQL_DATABASE=sample
MYSQL_ENV_MYSQL_MAJOR=5.6
MYSQL_ENV_MYSQL_VERSION=5.6.24
HOME=/root
* Use a one-shot Docker instance for a MySQL command-line interface. Once this
is running, you'll be able to use command like 'show databases'.
docker run -it \
--link=firstcompose_mysqldb_1:mysql \
--rm \
mysql/mysql-server:latest \
sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
That's all it takes to start.
* Install docker
* Install docker-compose
* mkdir firstdb
* cd firstdb
* vi docker-compose.yml
mysql:
image: mysql:latest
environment:
MYSQL_DATABASE: sample
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
MYSQL_ROOT_PASSWORD: supersecret
* docker-compose up
* docker-compose ps
Name Command State Ports
-----------------------------------------------------------------
firstdb_mysql_1 /entrypoint.sh mysqld Up 3306/tcp
* Use a one-shot Docker instance to display environment variables. Notice
the variables that start with MYSQL? Your programs can use these variables
to make the database connection.
docker run --link=firstdb_mysql_1:mysql ubuntu env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=abfc8d50633b
MYSQL_PORT=tcp://172.17.0.23:3306
MYSQL_PORT_3306_TCP=tcp://172.17.0.23:3306
MYSQL_PORT_3306_TCP_ADDR=172.17.0.23
MYSQL_PORT_3306_TCP_PORT=3306
MYSQL_PORT_3306_TCP_PROTO=tcp
MYSQL_NAME=/nostalgic_rosalind/mysqldb
MYSQL_ENV_MYSQL_PASSWORD=mysql
MYSQL_ENV_MYSQL_ROOT_PASSWORD=supersecret
MYSQL_ENV_MYSQL_USER=mysql
MYSQL_ENV_MYSQL_DATABASE=sample
MYSQL_ENV_MYSQL_MAJOR=5.6
MYSQL_ENV_MYSQL_VERSION=5.6.24
HOME=/root
* Use a one-shot Docker instance for a MySQL command-line interface. Once this
is running, you'll be able to use command like 'show databases'.
docker run -it \
--link=firstcompose_mysqldb_1:mysql \
--rm \
mysql/mysql-server:latest \
sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
That's all it takes to start.
11/23/2014: Using AZUL 7 instead of OpenJDK Java for smaller Docker images.
Witness a tale of two Dockerfiles that perform the same task. See the size difference. Imagine how it might change infrastructure costs.
Notice the only difference is which Java is being installed. Here are the image sizes:
That's a 288MB difference.
DOCKERFILE ONE
FROM debian:wheezy RUN apt-get update && apt-get install -y openjdk-7-jre && rm -rf /var/lib/apt/lists/* ADD target/si-standalone-sample-1.0-SNAPSHOT.jar / ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64 ENV CLASSPATH si-standalone-sample-1.0-SNAPSHOT.jar CMD [ "java", "org.springframework.boot.loader.JarLauncher" ]
DOCKERFILE TWO
FROM debian:wheezy RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0x219BD9C9 && \ echo "deb http://repos.azulsystems.com/ubuntu precise main" >> /etc/apt/sources.list.d/zulu.list && \ apt-get -qq update && \ apt-get -qqy install zulu-7 && \ rm -rf /var/lib/apt/lists/* ADD target/si-standalone-sample-1.0-SNAPSHOT.jar / ENV JAVA_HOME /usr/lib/jvm/zulu-7-amd64 ENV CLASSPATH si-standalone-sample-1.0-SNAPSHOT.jar CMD [ "java", "org.springframework.boot.loader.JarLauncher" ]
Notice the only difference is which Java is being installed. Here are the image sizes:
spring-integration openjdk 549.1 MB spring-integration azul 261.3 MB
That's a 288MB difference.