Huge static (mysql) database in docker
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am developing an application and try to implement the microservice architecture. For information about locations (cities, zip codes, etc.) I downloaded a database dump for mysql from opengeodb.org.
Now I want to provide the database as a docker container.
I set up a mysql image with following Dockerfile as mentioned in the docs for the mysql image:
FROM mysql
ENV MYSQL_ROOT_PASSWORD=mypassword
ENV MYSQL_DATABASE geodb
WORKDIR /docker-entrypoint-initdb.d
ADD ${PWD}/sql .
EXPOSE 3306
The "sql"-folder contains sql scripts with the raw data as insert statements, so it creates the whole database.The problem is, that the database is really huge and it takes really long to set it up.
So I thought, maybe there is a possibility to save the created database inside an image, because it is an static database for read-only operations only.
I am fairly new to docker and not quite sure how to achieve this.
I'm using docker on a Windows 10 machine.
EDIT:
I achieved my goal by doing the following:
- I added the sql dump file as described above.
- I ran the container and built the whole database with a local directory (the 'data' folder) mounted to /var/lib/mysql.
Then stopped the container and edited the Dockerfile:
FROM mysql
ENV MYSQL_ROOT_PASSWORD=mypassword
ENV MYSQL_DATABASE geodb
WORKDIR /var/lib/mysql
COPY ${PWD}data .
EXPOSE 3306
So the generated Database is now beeing copied from local system into the container.
mysql docker dockerfile
add a comment |
I am developing an application and try to implement the microservice architecture. For information about locations (cities, zip codes, etc.) I downloaded a database dump for mysql from opengeodb.org.
Now I want to provide the database as a docker container.
I set up a mysql image with following Dockerfile as mentioned in the docs for the mysql image:
FROM mysql
ENV MYSQL_ROOT_PASSWORD=mypassword
ENV MYSQL_DATABASE geodb
WORKDIR /docker-entrypoint-initdb.d
ADD ${PWD}/sql .
EXPOSE 3306
The "sql"-folder contains sql scripts with the raw data as insert statements, so it creates the whole database.The problem is, that the database is really huge and it takes really long to set it up.
So I thought, maybe there is a possibility to save the created database inside an image, because it is an static database for read-only operations only.
I am fairly new to docker and not quite sure how to achieve this.
I'm using docker on a Windows 10 machine.
EDIT:
I achieved my goal by doing the following:
- I added the sql dump file as described above.
- I ran the container and built the whole database with a local directory (the 'data' folder) mounted to /var/lib/mysql.
Then stopped the container and edited the Dockerfile:
FROM mysql
ENV MYSQL_ROOT_PASSWORD=mypassword
ENV MYSQL_DATABASE geodb
WORKDIR /var/lib/mysql
COPY ${PWD}data .
EXPOSE 3306
So the generated Database is now beeing copied from local system into the container.
mysql docker dockerfile
add a comment |
I am developing an application and try to implement the microservice architecture. For information about locations (cities, zip codes, etc.) I downloaded a database dump for mysql from opengeodb.org.
Now I want to provide the database as a docker container.
I set up a mysql image with following Dockerfile as mentioned in the docs for the mysql image:
FROM mysql
ENV MYSQL_ROOT_PASSWORD=mypassword
ENV MYSQL_DATABASE geodb
WORKDIR /docker-entrypoint-initdb.d
ADD ${PWD}/sql .
EXPOSE 3306
The "sql"-folder contains sql scripts with the raw data as insert statements, so it creates the whole database.The problem is, that the database is really huge and it takes really long to set it up.
So I thought, maybe there is a possibility to save the created database inside an image, because it is an static database for read-only operations only.
I am fairly new to docker and not quite sure how to achieve this.
I'm using docker on a Windows 10 machine.
EDIT:
I achieved my goal by doing the following:
- I added the sql dump file as described above.
- I ran the container and built the whole database with a local directory (the 'data' folder) mounted to /var/lib/mysql.
Then stopped the container and edited the Dockerfile:
FROM mysql
ENV MYSQL_ROOT_PASSWORD=mypassword
ENV MYSQL_DATABASE geodb
WORKDIR /var/lib/mysql
COPY ${PWD}data .
EXPOSE 3306
So the generated Database is now beeing copied from local system into the container.
mysql docker dockerfile
I am developing an application and try to implement the microservice architecture. For information about locations (cities, zip codes, etc.) I downloaded a database dump for mysql from opengeodb.org.
Now I want to provide the database as a docker container.
I set up a mysql image with following Dockerfile as mentioned in the docs for the mysql image:
FROM mysql
ENV MYSQL_ROOT_PASSWORD=mypassword
ENV MYSQL_DATABASE geodb
WORKDIR /docker-entrypoint-initdb.d
ADD ${PWD}/sql .
EXPOSE 3306
The "sql"-folder contains sql scripts with the raw data as insert statements, so it creates the whole database.The problem is, that the database is really huge and it takes really long to set it up.
So I thought, maybe there is a possibility to save the created database inside an image, because it is an static database for read-only operations only.
I am fairly new to docker and not quite sure how to achieve this.
I'm using docker on a Windows 10 machine.
EDIT:
I achieved my goal by doing the following:
- I added the sql dump file as described above.
- I ran the container and built the whole database with a local directory (the 'data' folder) mounted to /var/lib/mysql.
Then stopped the container and edited the Dockerfile:
FROM mysql
ENV MYSQL_ROOT_PASSWORD=mypassword
ENV MYSQL_DATABASE geodb
WORKDIR /var/lib/mysql
COPY ${PWD}data .
EXPOSE 3306
So the generated Database is now beeing copied from local system into the container.
mysql docker dockerfile
mysql docker dockerfile
edited Nov 25 '18 at 14:28
Ragnar
asked Nov 25 '18 at 10:55
RagnarRagnar
105
105
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You could create a volume with your container to persist the database on your local machine. When you first create the container, the SQL in /docker-entrypoint-initdb.d
will be executed, and the changes will be stored to the volume. Next time you start the container, MySQL will see that the schema already exists and it won't run the scripts again.
https://docs.docker.com/storage/volumes/
So I could first let it create the database from the dump file, storing it in my mounted folder and then after the creation has finished just ADD the files within the Dockerfile, so it never has to recreate the database...
– Ragnar
Nov 25 '18 at 11:21
No, you don't need to mount a folder. Just create a named volume (with the-v
flag) when you create your container, and ADD the files as usual.
– linguamachina
Nov 25 '18 at 11:24
Okay I understand. I thought of a portable image of the whole database, so when i run the image on any other machine it has the whole database ready. When i'm using the -v flag the database is only stored inside docker on my machine. Please correct me, if i'm wrong. :-)
– Ragnar
Nov 25 '18 at 11:31
@Ragnar you're right. However, you can transfer volumes to other machines - the process isn't straightforward, but it can be done (although I never have, so I can't help you there)
– linguamachina
Nov 25 '18 at 11:35
Thanks! I didn't know that.
– Ragnar
Nov 25 '18 at 11:42
add a comment |
In principle you could achieve it like this:
- start the container
- load the database
- perform a
docker commit
to build an image of the current state of the container.
The other option would be to load in the database during the image build time, but for this you would have to start mysql similarly to how it's done in the entrypoint script.
- start mysql in background
- wait for it to initialize
- load in the data using
mysql < sql file
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%2f53466754%2fhuge-static-mysql-database-in-docker%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could create a volume with your container to persist the database on your local machine. When you first create the container, the SQL in /docker-entrypoint-initdb.d
will be executed, and the changes will be stored to the volume. Next time you start the container, MySQL will see that the schema already exists and it won't run the scripts again.
https://docs.docker.com/storage/volumes/
So I could first let it create the database from the dump file, storing it in my mounted folder and then after the creation has finished just ADD the files within the Dockerfile, so it never has to recreate the database...
– Ragnar
Nov 25 '18 at 11:21
No, you don't need to mount a folder. Just create a named volume (with the-v
flag) when you create your container, and ADD the files as usual.
– linguamachina
Nov 25 '18 at 11:24
Okay I understand. I thought of a portable image of the whole database, so when i run the image on any other machine it has the whole database ready. When i'm using the -v flag the database is only stored inside docker on my machine. Please correct me, if i'm wrong. :-)
– Ragnar
Nov 25 '18 at 11:31
@Ragnar you're right. However, you can transfer volumes to other machines - the process isn't straightforward, but it can be done (although I never have, so I can't help you there)
– linguamachina
Nov 25 '18 at 11:35
Thanks! I didn't know that.
– Ragnar
Nov 25 '18 at 11:42
add a comment |
You could create a volume with your container to persist the database on your local machine. When you first create the container, the SQL in /docker-entrypoint-initdb.d
will be executed, and the changes will be stored to the volume. Next time you start the container, MySQL will see that the schema already exists and it won't run the scripts again.
https://docs.docker.com/storage/volumes/
So I could first let it create the database from the dump file, storing it in my mounted folder and then after the creation has finished just ADD the files within the Dockerfile, so it never has to recreate the database...
– Ragnar
Nov 25 '18 at 11:21
No, you don't need to mount a folder. Just create a named volume (with the-v
flag) when you create your container, and ADD the files as usual.
– linguamachina
Nov 25 '18 at 11:24
Okay I understand. I thought of a portable image of the whole database, so when i run the image on any other machine it has the whole database ready. When i'm using the -v flag the database is only stored inside docker on my machine. Please correct me, if i'm wrong. :-)
– Ragnar
Nov 25 '18 at 11:31
@Ragnar you're right. However, you can transfer volumes to other machines - the process isn't straightforward, but it can be done (although I never have, so I can't help you there)
– linguamachina
Nov 25 '18 at 11:35
Thanks! I didn't know that.
– Ragnar
Nov 25 '18 at 11:42
add a comment |
You could create a volume with your container to persist the database on your local machine. When you first create the container, the SQL in /docker-entrypoint-initdb.d
will be executed, and the changes will be stored to the volume. Next time you start the container, MySQL will see that the schema already exists and it won't run the scripts again.
https://docs.docker.com/storage/volumes/
You could create a volume with your container to persist the database on your local machine. When you first create the container, the SQL in /docker-entrypoint-initdb.d
will be executed, and the changes will be stored to the volume. Next time you start the container, MySQL will see that the schema already exists and it won't run the scripts again.
https://docs.docker.com/storage/volumes/
answered Nov 25 '18 at 11:05
linguamachinalinguamachina
2,23411318
2,23411318
So I could first let it create the database from the dump file, storing it in my mounted folder and then after the creation has finished just ADD the files within the Dockerfile, so it never has to recreate the database...
– Ragnar
Nov 25 '18 at 11:21
No, you don't need to mount a folder. Just create a named volume (with the-v
flag) when you create your container, and ADD the files as usual.
– linguamachina
Nov 25 '18 at 11:24
Okay I understand. I thought of a portable image of the whole database, so when i run the image on any other machine it has the whole database ready. When i'm using the -v flag the database is only stored inside docker on my machine. Please correct me, if i'm wrong. :-)
– Ragnar
Nov 25 '18 at 11:31
@Ragnar you're right. However, you can transfer volumes to other machines - the process isn't straightforward, but it can be done (although I never have, so I can't help you there)
– linguamachina
Nov 25 '18 at 11:35
Thanks! I didn't know that.
– Ragnar
Nov 25 '18 at 11:42
add a comment |
So I could first let it create the database from the dump file, storing it in my mounted folder and then after the creation has finished just ADD the files within the Dockerfile, so it never has to recreate the database...
– Ragnar
Nov 25 '18 at 11:21
No, you don't need to mount a folder. Just create a named volume (with the-v
flag) when you create your container, and ADD the files as usual.
– linguamachina
Nov 25 '18 at 11:24
Okay I understand. I thought of a portable image of the whole database, so when i run the image on any other machine it has the whole database ready. When i'm using the -v flag the database is only stored inside docker on my machine. Please correct me, if i'm wrong. :-)
– Ragnar
Nov 25 '18 at 11:31
@Ragnar you're right. However, you can transfer volumes to other machines - the process isn't straightforward, but it can be done (although I never have, so I can't help you there)
– linguamachina
Nov 25 '18 at 11:35
Thanks! I didn't know that.
– Ragnar
Nov 25 '18 at 11:42
So I could first let it create the database from the dump file, storing it in my mounted folder and then after the creation has finished just ADD the files within the Dockerfile, so it never has to recreate the database...
– Ragnar
Nov 25 '18 at 11:21
So I could first let it create the database from the dump file, storing it in my mounted folder and then after the creation has finished just ADD the files within the Dockerfile, so it never has to recreate the database...
– Ragnar
Nov 25 '18 at 11:21
No, you don't need to mount a folder. Just create a named volume (with the
-v
flag) when you create your container, and ADD the files as usual.– linguamachina
Nov 25 '18 at 11:24
No, you don't need to mount a folder. Just create a named volume (with the
-v
flag) when you create your container, and ADD the files as usual.– linguamachina
Nov 25 '18 at 11:24
Okay I understand. I thought of a portable image of the whole database, so when i run the image on any other machine it has the whole database ready. When i'm using the -v flag the database is only stored inside docker on my machine. Please correct me, if i'm wrong. :-)
– Ragnar
Nov 25 '18 at 11:31
Okay I understand. I thought of a portable image of the whole database, so when i run the image on any other machine it has the whole database ready. When i'm using the -v flag the database is only stored inside docker on my machine. Please correct me, if i'm wrong. :-)
– Ragnar
Nov 25 '18 at 11:31
@Ragnar you're right. However, you can transfer volumes to other machines - the process isn't straightforward, but it can be done (although I never have, so I can't help you there)
– linguamachina
Nov 25 '18 at 11:35
@Ragnar you're right. However, you can transfer volumes to other machines - the process isn't straightforward, but it can be done (although I never have, so I can't help you there)
– linguamachina
Nov 25 '18 at 11:35
Thanks! I didn't know that.
– Ragnar
Nov 25 '18 at 11:42
Thanks! I didn't know that.
– Ragnar
Nov 25 '18 at 11:42
add a comment |
In principle you could achieve it like this:
- start the container
- load the database
- perform a
docker commit
to build an image of the current state of the container.
The other option would be to load in the database during the image build time, but for this you would have to start mysql similarly to how it's done in the entrypoint script.
- start mysql in background
- wait for it to initialize
- load in the data using
mysql < sql file
add a comment |
In principle you could achieve it like this:
- start the container
- load the database
- perform a
docker commit
to build an image of the current state of the container.
The other option would be to load in the database during the image build time, but for this you would have to start mysql similarly to how it's done in the entrypoint script.
- start mysql in background
- wait for it to initialize
- load in the data using
mysql < sql file
add a comment |
In principle you could achieve it like this:
- start the container
- load the database
- perform a
docker commit
to build an image of the current state of the container.
The other option would be to load in the database during the image build time, but for this you would have to start mysql similarly to how it's done in the entrypoint script.
- start mysql in background
- wait for it to initialize
- load in the data using
mysql < sql file
In principle you could achieve it like this:
- start the container
- load the database
- perform a
docker commit
to build an image of the current state of the container.
The other option would be to load in the database during the image build time, but for this you would have to start mysql similarly to how it's done in the entrypoint script.
- start mysql in background
- wait for it to initialize
- load in the data using
mysql < sql file
answered Nov 25 '18 at 11:53
Uku LoskitUku Loskit
31.3k87282
31.3k87282
add a comment |
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%2f53466754%2fhuge-static-mysql-database-in-docker%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