Dockerizing Java application using exclusive MySQL DB
I have a Java application that needs a MySQL/MariaDB database in order to work. My goal is to build a standalone Docker image for it. I have looked up a number of tutorials but they seem to contradict what I want to achieve. This makes me doubt whether my goal is appropriate in the first place, but I still can't see why it wouldn't be a reasonable one.
I do not care for sharing the MySQL server to have multiple databases on it. It's only important that the DB of the application be there, nothing else.
What is the right way to proceed to build such a Docker image?
Do I make two containers with docker-compose, one for the DB and one for the Java application? That's what most seem to suggest, but I want an image that can just be pulled from a registry and will work out of the box.
Do I make a single image FROM a MySQL/MariaDB image and add Java and my application to it?
Do I make a single image FROM an OpenJDK image and add MySQL/MariaDB and my application to it?
is there another way to proceed?
Many thanks
java mysql docker docker-compose mariadb
add a comment |
I have a Java application that needs a MySQL/MariaDB database in order to work. My goal is to build a standalone Docker image for it. I have looked up a number of tutorials but they seem to contradict what I want to achieve. This makes me doubt whether my goal is appropriate in the first place, but I still can't see why it wouldn't be a reasonable one.
I do not care for sharing the MySQL server to have multiple databases on it. It's only important that the DB of the application be there, nothing else.
What is the right way to proceed to build such a Docker image?
Do I make two containers with docker-compose, one for the DB and one for the Java application? That's what most seem to suggest, but I want an image that can just be pulled from a registry and will work out of the box.
Do I make a single image FROM a MySQL/MariaDB image and add Java and my application to it?
Do I make a single image FROM an OpenJDK image and add MySQL/MariaDB and my application to it?
is there another way to proceed?
Many thanks
java mysql docker docker-compose mariadb
add a comment |
I have a Java application that needs a MySQL/MariaDB database in order to work. My goal is to build a standalone Docker image for it. I have looked up a number of tutorials but they seem to contradict what I want to achieve. This makes me doubt whether my goal is appropriate in the first place, but I still can't see why it wouldn't be a reasonable one.
I do not care for sharing the MySQL server to have multiple databases on it. It's only important that the DB of the application be there, nothing else.
What is the right way to proceed to build such a Docker image?
Do I make two containers with docker-compose, one for the DB and one for the Java application? That's what most seem to suggest, but I want an image that can just be pulled from a registry and will work out of the box.
Do I make a single image FROM a MySQL/MariaDB image and add Java and my application to it?
Do I make a single image FROM an OpenJDK image and add MySQL/MariaDB and my application to it?
is there another way to proceed?
Many thanks
java mysql docker docker-compose mariadb
I have a Java application that needs a MySQL/MariaDB database in order to work. My goal is to build a standalone Docker image for it. I have looked up a number of tutorials but they seem to contradict what I want to achieve. This makes me doubt whether my goal is appropriate in the first place, but I still can't see why it wouldn't be a reasonable one.
I do not care for sharing the MySQL server to have multiple databases on it. It's only important that the DB of the application be there, nothing else.
What is the right way to proceed to build such a Docker image?
Do I make two containers with docker-compose, one for the DB and one for the Java application? That's what most seem to suggest, but I want an image that can just be pulled from a registry and will work out of the box.
Do I make a single image FROM a MySQL/MariaDB image and add Java and my application to it?
Do I make a single image FROM an OpenJDK image and add MySQL/MariaDB and my application to it?
is there another way to proceed?
Many thanks
java mysql docker docker-compose mariadb
java mysql docker docker-compose mariadb
asked Nov 14 '18 at 11:13
alexdmaalexdma
62
62
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
A docker image is designed to run a single command, so although you could add your application files to a MySQL image (or vice-versa), you would struggle to get both running.
You were heading down the right track with docker-compose - that would let you define the two containers and how they’re run. This may actually give you a simpler deployment than standalone containers.
You may also wish to consider not shipping a MySQL container at all. Why not give your application the ability to create the required database, and add a config option for the user to tell it where to find the database server? If the user chooses to use a dockerized MySQL instance, they can just pull the vanilla mysql:latest image and configure the ports themselves.
Or once you’ve added that functionality to your application, you could then ship a Compose solution with the vanilla MySQL instance, requiring only one custom Dockerfile.
Thanks, but I'm afraid I still don't quite understand: If I make it a combination of containers, doesn't it mean that the image of my application will never be able to run by itself? Doesn't that negate the magic of "you pull it from the registry and it just works because it's got everything it needs inside it"?
– alexdma
Nov 14 '18 at 13:37
1
That’s not the Docker magic. It’s an effective portable packaging around a single process and its dependencies that isolates the storage and network setups (I can configure both MySQL and PostgreSQL to listen on alternate ports in the same way without learning either database’s local configuration, for example). Pretty much every real useful Docker-based application requires multiple containers, and that’s normal.
– David Maze
Nov 14 '18 at 14:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298908%2fdockerizing-java-application-using-exclusive-mysql-db%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
A docker image is designed to run a single command, so although you could add your application files to a MySQL image (or vice-versa), you would struggle to get both running.
You were heading down the right track with docker-compose - that would let you define the two containers and how they’re run. This may actually give you a simpler deployment than standalone containers.
You may also wish to consider not shipping a MySQL container at all. Why not give your application the ability to create the required database, and add a config option for the user to tell it where to find the database server? If the user chooses to use a dockerized MySQL instance, they can just pull the vanilla mysql:latest image and configure the ports themselves.
Or once you’ve added that functionality to your application, you could then ship a Compose solution with the vanilla MySQL instance, requiring only one custom Dockerfile.
Thanks, but I'm afraid I still don't quite understand: If I make it a combination of containers, doesn't it mean that the image of my application will never be able to run by itself? Doesn't that negate the magic of "you pull it from the registry and it just works because it's got everything it needs inside it"?
– alexdma
Nov 14 '18 at 13:37
1
That’s not the Docker magic. It’s an effective portable packaging around a single process and its dependencies that isolates the storage and network setups (I can configure both MySQL and PostgreSQL to listen on alternate ports in the same way without learning either database’s local configuration, for example). Pretty much every real useful Docker-based application requires multiple containers, and that’s normal.
– David Maze
Nov 14 '18 at 14:39
add a comment |
A docker image is designed to run a single command, so although you could add your application files to a MySQL image (or vice-versa), you would struggle to get both running.
You were heading down the right track with docker-compose - that would let you define the two containers and how they’re run. This may actually give you a simpler deployment than standalone containers.
You may also wish to consider not shipping a MySQL container at all. Why not give your application the ability to create the required database, and add a config option for the user to tell it where to find the database server? If the user chooses to use a dockerized MySQL instance, they can just pull the vanilla mysql:latest image and configure the ports themselves.
Or once you’ve added that functionality to your application, you could then ship a Compose solution with the vanilla MySQL instance, requiring only one custom Dockerfile.
Thanks, but I'm afraid I still don't quite understand: If I make it a combination of containers, doesn't it mean that the image of my application will never be able to run by itself? Doesn't that negate the magic of "you pull it from the registry and it just works because it's got everything it needs inside it"?
– alexdma
Nov 14 '18 at 13:37
1
That’s not the Docker magic. It’s an effective portable packaging around a single process and its dependencies that isolates the storage and network setups (I can configure both MySQL and PostgreSQL to listen on alternate ports in the same way without learning either database’s local configuration, for example). Pretty much every real useful Docker-based application requires multiple containers, and that’s normal.
– David Maze
Nov 14 '18 at 14:39
add a comment |
A docker image is designed to run a single command, so although you could add your application files to a MySQL image (or vice-versa), you would struggle to get both running.
You were heading down the right track with docker-compose - that would let you define the two containers and how they’re run. This may actually give you a simpler deployment than standalone containers.
You may also wish to consider not shipping a MySQL container at all. Why not give your application the ability to create the required database, and add a config option for the user to tell it where to find the database server? If the user chooses to use a dockerized MySQL instance, they can just pull the vanilla mysql:latest image and configure the ports themselves.
Or once you’ve added that functionality to your application, you could then ship a Compose solution with the vanilla MySQL instance, requiring only one custom Dockerfile.
A docker image is designed to run a single command, so although you could add your application files to a MySQL image (or vice-versa), you would struggle to get both running.
You were heading down the right track with docker-compose - that would let you define the two containers and how they’re run. This may actually give you a simpler deployment than standalone containers.
You may also wish to consider not shipping a MySQL container at all. Why not give your application the ability to create the required database, and add a config option for the user to tell it where to find the database server? If the user chooses to use a dockerized MySQL instance, they can just pull the vanilla mysql:latest image and configure the ports themselves.
Or once you’ve added that functionality to your application, you could then ship a Compose solution with the vanilla MySQL instance, requiring only one custom Dockerfile.
answered Nov 14 '18 at 11:29
MTCosterMTCoster
3,68122141
3,68122141
Thanks, but I'm afraid I still don't quite understand: If I make it a combination of containers, doesn't it mean that the image of my application will never be able to run by itself? Doesn't that negate the magic of "you pull it from the registry and it just works because it's got everything it needs inside it"?
– alexdma
Nov 14 '18 at 13:37
1
That’s not the Docker magic. It’s an effective portable packaging around a single process and its dependencies that isolates the storage and network setups (I can configure both MySQL and PostgreSQL to listen on alternate ports in the same way without learning either database’s local configuration, for example). Pretty much every real useful Docker-based application requires multiple containers, and that’s normal.
– David Maze
Nov 14 '18 at 14:39
add a comment |
Thanks, but I'm afraid I still don't quite understand: If I make it a combination of containers, doesn't it mean that the image of my application will never be able to run by itself? Doesn't that negate the magic of "you pull it from the registry and it just works because it's got everything it needs inside it"?
– alexdma
Nov 14 '18 at 13:37
1
That’s not the Docker magic. It’s an effective portable packaging around a single process and its dependencies that isolates the storage and network setups (I can configure both MySQL and PostgreSQL to listen on alternate ports in the same way without learning either database’s local configuration, for example). Pretty much every real useful Docker-based application requires multiple containers, and that’s normal.
– David Maze
Nov 14 '18 at 14:39
Thanks, but I'm afraid I still don't quite understand: If I make it a combination of containers, doesn't it mean that the image of my application will never be able to run by itself? Doesn't that negate the magic of "you pull it from the registry and it just works because it's got everything it needs inside it"?
– alexdma
Nov 14 '18 at 13:37
Thanks, but I'm afraid I still don't quite understand: If I make it a combination of containers, doesn't it mean that the image of my application will never be able to run by itself? Doesn't that negate the magic of "you pull it from the registry and it just works because it's got everything it needs inside it"?
– alexdma
Nov 14 '18 at 13:37
1
1
That’s not the Docker magic. It’s an effective portable packaging around a single process and its dependencies that isolates the storage and network setups (I can configure both MySQL and PostgreSQL to listen on alternate ports in the same way without learning either database’s local configuration, for example). Pretty much every real useful Docker-based application requires multiple containers, and that’s normal.
– David Maze
Nov 14 '18 at 14:39
That’s not the Docker magic. It’s an effective portable packaging around a single process and its dependencies that isolates the storage and network setups (I can configure both MySQL and PostgreSQL to listen on alternate ports in the same way without learning either database’s local configuration, for example). Pretty much every real useful Docker-based application requires multiple containers, and that’s normal.
– David Maze
Nov 14 '18 at 14:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298908%2fdockerizing-java-application-using-exclusive-mysql-db%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown