Skip to content

Commit 3bbc33c

Browse files
committed
Add docker compose post for elasticsearch and mysql. Fix another css issue with code snippets.
1 parent 11e0ded commit 3bbc33c

File tree

5 files changed

+109
-7
lines changed

5 files changed

+109
-7
lines changed

docker/docker-compose.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services:
33
elasticsearch:
44
image: docker.elastic.co/elasticsearch/elasticsearch:5.6.1
55
restart: always
6-
container_name: elasticsearch
6+
container_name: stubbornjava_elasticsearch
77
environment:
88
- node.name=stubbornjava
99
- cluster.name=stubbornjava-cluster
@@ -22,22 +22,23 @@ services:
2222
soft: -1
2323
hard: -1
2424
volumes:
25-
- esdata:/usr/share/elasticsearch/data
25+
- stubbornjava_esdata:/usr/share/elasticsearch/data
2626
ports:
2727
- 9200:9200
2828
mysql:
2929
build: mysql
3030
restart: always
31+
container_name: stubbornjava_mysql
3132
environment:
3233
- MYSQL_ROOT_PASSWORD=
3334
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
3435
ports:
3536
- "3306:3306"
3637
volumes:
37-
- mysql:/var/lib/mysql
38+
- stubbornjava_mysql:/var/lib/mysql
3839

3940
volumes:
40-
esdata:
41+
stubbornjava_esdata:
4142
driver: local
42-
mysql:
43+
stubbornjava_mysql:
4344
driver: local

stubbornjava-webapp/src/main/java/com/stubbornjava/webapp/post/PostData.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,30 @@ public class PostData {
664664
))
665665
.build()
666666
);
667+
posts.add(PostRaw.builder()
668+
.postId(1L)
669+
.title("Creating a local development environment with Docker Compose")
670+
.metaDesc("Setting up MySQL and Elasticsearch locally with Docker Compose to simplify your development environment.")
671+
.dateCreated(LocalDateTime.parse("2017-10-24T01:15:30"))
672+
.dateUpdated(LocalDateTime.parse("2017-10-24T01:15:30"))
673+
.javaLibs(Lists.newArrayList())
674+
.tags(Lists.newArrayList(Tags.Docker, Tags.MySQL, Tags.Elasticsearch))
675+
.gitFileReferences(Lists.newArrayList(
676+
FileReference.stubbornJava(
677+
"dockerCompose",
678+
"docker/docker-compose.yml")
679+
, FileReference.stubbornJava(
680+
"mysql",
681+
"docker/mysql/Dockerfile")
682+
, FileReference.stubbornJava(
683+
"mysqlcnf",
684+
"docker/mysql/mysqld.cnf")
685+
, FileReference.stubbornJava(
686+
"mysqlSetup",
687+
"docker/mysql/setup.sh")
688+
))
689+
.build()
690+
);
667691
}
668692

669693
public static List<PostRaw> getPosts() {

stubbornjava-webapp/src/main/java/com/stubbornjava/webapp/post/Tags.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public class Tags {
2525
public static final Tag Microservice = addTag(new Tag(897667693917183622L, "Microservice"));
2626
public static final Tag Monolith = addTag(new Tag(897667693920667427L, "Monolith"));
2727
public static final Tag Caching = addTag(new Tag(905411988101360294L, "Caching"));
28+
public static final Tag Docker = addTag(new Tag(922789907642700121L, "Docker"));
29+
public static final Tag MySQL = addTag(new Tag(922794262771082027L, "MySQL"));
30+
public static final Tag Elasticsearch = addTag(new Tag(922794262770139008L, "Elasticsearch"));
2831

2932
private static Tag addTag(Tag tag) {
3033
TAGS.add(tag);

stubbornjava-webapp/ui/src/common/prism-coy-override.scss

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
@import './skin.scss';
22
@import '../widgets/common/depth.scss';
33

4-
pre[class*=language-]>code {
5-
border-left-color: $theme;
4+
pre[class*=language-] {
65

76
@extend .z-depth-1;
7+
8+
&>code {
9+
border-left-color: $theme;
10+
box-shadow: inherit;
11+
}
812
&:before, &:after {
913
box-shadow: inherit;
1014
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<div class="anchored-md">
2+
{{#assign "markdown"}}
3+
Creating a simple and reliable development environment is essential to developer productivity as well as on-boarding new team members. It's far too common for companies to have extremely intricate and fragile development environments. Teams should constantly be improving their local development environments. Small annoyances here and there may not seem like much but remember it impacts every developer using that code base. Let's take a look at one of the most more difficult parts of a developer environment, data stores. We will see how to manage them cross platform utilizing [Docker Compose](https://docs.docker.com/compose/).
4+
5+
## What is Docker?
6+
According to their website "[Docker](https://www.docker.com/) is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud." In layman's terms it's basically an image containing a low level OS and all software preconfigured. Essentially a much more lightweight VM image. Multiple docker containers can run in a single OS unlike VMs where each VM runs an OS of its own eating up resources. Containers can be anything along the lines of a database, document store, message broker, search service, an existing application, or anything else you can think of. Our use case is quite simple, we want [MySQL](https://www.mysql.com/) and [Elasticsearch](https://www.elastic.co/) running in our development environment without the need to manually install them. This also gives us flexibility to have different docker compose files for different applications and have no need to worry about naming conflicts or different versions of a dependency across projects.
7+
8+
### Docker Hub
9+
[Docker Hub](https://hub.docker.com/) is a repository of shared docker containers you can readily import. We will be using it as the base for our MySQL and Elasticsearch containers.
10+
11+
### Docker Compose
12+
[Docker Compose](https://docs.docker.com/compose/) is a tool for defining and running multi-container Docker applications. Each application we have can have it's own docker compose file for a single command boot up of our development environment. Below is our StubbornJava docker compose file. We will take a look at each container later.
13+
14+
{{> templates/src/widgets/code/code-snippet file=dockerCompose section=dockerCompose.content language=yml}}
15+
16+
## MySQL Container
17+
We are starting with a base MySQL docker image from Docker Hub and adding some customizations to the `my.cnf` file. Mainly we want to support full unicode using `utf8mb4` see [MySQL 8.0: When to use utf8mb3 over utf8mb4?](http://mysqlserverteam.com/mysql-8-0-when-to-use-utf8mb3-over-utf8mb4/) for more info.
18+
19+
### MySQL Dockerfile
20+
Starting with our base docker image we then apply our custom `my.cnf` file as well as run a script to help configure things such as creating databases or users.
21+
22+
{{> templates/src/widgets/code/code-snippet file=mysql section=mysql.content}}
23+
24+
### MySQL my.cnf
25+
Our custom mysql config file.
26+
27+
{{> templates/src/widgets/code/code-snippet file=mysqlcnf section=mysqlcnf.content}}
28+
29+
### MySQL Setup script
30+
Create databases and users or anything else needed to bootstrap.
31+
32+
{{> templates/src/widgets/code/code-snippet file=mysqlSetup section=mysqlSetup.content}}
33+
34+
## Elasticsearch Contianer
35+
Since we are just using the default ES container we don't need a separate Dockerfile here. All of the configuration can be passed in directly from the docker compose file. Take note this is a single server set up which is probably ok for local development or small projects but you will probably want a better setup for non local environments.
36+
37+
## Running the dev environment
38+
Simply change directory to where the docker compose file lives and run `docker-compose up`. You should see logs coming from both containers and you should be up and running.
39+
40+
<pre class="line-numbers"><code class="language-bash">mysql -u root --host=localhost --protocol=tcp -e 'SHOW DATABASES';
41+
+--------------------+
42+
| Database |
43+
+--------------------+
44+
| information_schema |
45+
| mysql |
46+
| performance_schema |
47+
| stubbornjava |
48+
| sys |
49+
+--------------------+</code></pre>
50+
You need to specify `protocol=tcp` since mysql is running in a container. You can also share a socket file between the volume and local OS.
51+
52+
<pre class="line-numbers"><code class="language-bash">curl localhost:9200
53+
{
54+
"name" : "stubbornjava",
55+
"cluster_name" : "stubbornjava-cluster",
56+
"cluster_uuid" : "-2ALiVFtTr6iJZkip8KXzA",
57+
"version" : {
58+
"number" : "5.6.1",
59+
"build_hash" : "667b497",
60+
"build_date" : "2017-09-14T19:22:05.189Z",
61+
"build_snapshot" : false,
62+
"lucene_version" : "6.6.1"
63+
},
64+
"tagline" : "You Know, for Search"
65+
}</code></pre>
66+
67+
Both MySQL and Elasticsearch are up and running.
68+
{{/assign}}
69+
{{md markdown}}
70+
</div>

0 commit comments

Comments
 (0)