20 Commits

Author SHA1 Message Date
asif 2a5f5eb556 chore(ide): update docker build config 2022-02-19 07:54:04 -07:00
asif af07af2015 fix(Dockerfile): fix apk update command 2022-02-19 07:42:30 -07:00
asif 3e4ea22d92 feature(Dockerfile): update base image 2022-02-19 07:40:56 -07:00
asif 036cac764c feature(Dockerfile): add dockerignore 2022-02-19 07:34:40 -07:00
asif 442b3921b7 chore(ide): docker build configuration for Rider 2022-02-19 07:33:35 -07:00
asif f3627e136a fix(Dockerfile): fix image title 2022-02-19 07:32:17 -07:00
asif 8b3fc0886f refactor(Dockerfile): set minimum versions 2022-02-19 07:30:34 -07:00
asif b9d8fa20c2 refactor(Dockerfile): parameterize versions 2022-02-19 07:27:01 -07:00
asif 6bf6c283d7 refactor(Dockerfile): update labels
- modernize labels
- split into stable and frequently updated
- place frequently updated at end of file
- update versioning structure
2022-02-19 07:26:28 -07:00
Asif Bacchus 09752089d6 update labels, bump version number 2021-05-12 21:33:59 -06:00
Asif Bacchus e4ea780a12 fix(entrypoint): only show passwd if generated 2021-05-12 20:55:55 -06:00
Asif Bacchus 0fb3dd427c Revert "fix(entrypoint): fix missing db name for SQL import"
This reverts commit 1630094cf7.
2021-05-01 08:15:49 -06:00
Asif Bacchus 1630094cf7 fix(entrypoint): fix missing db name for SQL import 2021-05-01 07:56:44 -06:00
Asif Bacchus ee29f71ff0 chore: remove VSCode files 2021-05-01 07:00:15 -06:00
Asif Bacchus 7f930e17e7 feature: bump Alpine and MariaDB versions
- Alpine to 3.13
- MariaDB to 10.5.9
2021-05-01 06:59:20 -06:00
Asif Bacchus 2b7c54ead7 docs(README): fix wrong repo name 2021-01-05 16:49:31 -07:00
Asif Bacchus be539440e4 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	README.md
2021-01-05 16:45:38 -07:00
Asif Bacchus 93b1212676 docs(README): use dockerhub as primary reference 2021-01-05 16:41:49 -07:00
Asif Bacchus 402e5217a3 docs(README): use dockerhub as primary reference 2021-01-05 16:39:20 -07:00
Asif Bacchus 797777d547 chore(LABELS): revert incorrect label change
mariadb version was correct previously
2021-01-05 16:12:02 -07:00
9 changed files with 119 additions and 45 deletions
+3
View File
@@ -0,0 +1,3 @@
/**
!Dockerfile
!entrypoint.sh
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitToolBoxProjectSettings">
<option name="commitMessageIssueKeyValidationOverride">
<BoolValueOverride>
<option name="enabled" value="true" />
</BoolValueOverride>
</option>
<option name="commitMessageValidationConfigOverride">
<CommitMessageValidationOverride>
<option name="enabled" value="true" />
</CommitMessageValidationOverride>
</option>
</component>
</project>
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ContentModelUserStore"> <component name="UserContentModel">
<attachedFolders /> <attachedFolders />
<explicitIncludes /> <explicitIncludes />
<explicitExcludes /> <explicitExcludes />
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownSettings">
<enabledExtensions>
<entry key="MermaidLanguageExtension" value="false" />
<entry key="PlantUMLLanguageExtension" value="false" />
</enabledExtensions>
</component>
</project>
+28
View File
@@ -0,0 +1,28 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker LOCAL">
<deployment type="dockerfile">
<settings>
<option name="imageTag" value="docker.asifbacchus.dev/mariadb/ab-mariadb-alpine:10.5.13" />
<option name="buildArgs">
<list>
<DockerEnvVarImpl>
<option name="name" value="INTERNAL_VERSION" />
<option name="value" value="1.2" />
</DockerEnvVarImpl>
<DockerEnvVarImpl>
<option name="name" value="GIT_COMMIT" />
<option name="value" value="af07af2015" />
</DockerEnvVarImpl>
<DockerEnvVarImpl>
<option name="name" value="BUILD_DATE" />
<option name="value" value="2022-02-19" />
</DockerEnvVarImpl>
</list>
</option>
<option name="buildOnly" value="true" />
<option name="sourceFilePath" value="Dockerfile" />
</settings>
</deployment>
<method v="2" />
</configuration>
</component>
-3
View File
@@ -1,3 +0,0 @@
{
"bookmarks": []
}
+31 -19
View File
@@ -1,26 +1,33 @@
# #
### mariadb running on Alpine Linux # mariadb running on Alpine Linux
# #
FROM alpine:3.12 # version arguments
ARG ALPINE_VERSION="3.14"
ARG MARIADB_VERSION="10.5.13-r0"
FROM alpine:${ALPINE_VERSION}
ARG ALPINE_VERSION
ARG MARIADB_VERSION
# standardized labels # standardized labels
LABEL maintainer="Asif Bacchus <asif@bacchus.cloud>" MAINTAINER Asif Bacchus <asif@asifbacchus.dev>
LABEL org.label-schema.cmd="docker run -d --name db -v volume:/var/lib/mysql [-v /pre/exec/scripts:/docker-entrypoint-preinit.d] [-v /sql/scripts:/docker-entrypoint-initdb.d] [-v /post/exec/scripts:/docker-entrypoint-postinit.d] [-e TZ=Etc/UTC -e MYSQL_UID=8100 -e MYSQL_GID=8100 -e MYSQL_ROOT_PASSWORD=... -e MYSQL_DATABASE='myData' -e MYSQL_CHARSET='utf8mb4' -e MYSQL_COLLATION='utf8mb4_general_ci' -e MYSQL_USER=... -e MYSQL_PASSWORD=...] docker.asifbacchus.app/mariadb/ab-mariadb-alpine:latest" LABEL dev.asifbacchus.docker.internalName="ab-mariadb-alpine"
LABEL org.label-schema.description="mariadb running on Alpine Linux." LABEL org.opencontainer.image.authors="Asif Bacchus <asif@asifbacchus.dev>"
LABEL org.label-schema.name="ab-mariadb-alpine" LABEL org.opencontainer.image.description="Mariadb on Alpine Linux."
LABEL org.label-schema.schema-version="1.0" LABEL org.opencontainer.image.documentation="https://git.asifbacchus.dev/ab-docker/ab-mariadb-alpine/raw/branch/main/README.md"
LABEL org.label-schema.url="https://git.asifbacchus.app/ab-docker/ab-mariadb-alpine" LABEL org.opencontainer.image.source="https://git.asifbacchus.dev/ab-docker/ab-mariadb-alpine.git"
LABEL org.label-schema.usage="https://git.asifbacchus.app/ab-docker/ab-mariadb-alpine/src/branch/master/README.md" LABEL org.opencontainer.image.title="ab-mariadb-alpine"
LABEL org.label-schema.vcs-url="https://git.asifbacchus.app/ab-docker/ab-mariadb-alpine.git" LABEL org.opencontainer.image.url="https://git.asifbacchus.dev/ab-docker/ab-mariadb-alpine"
LABEL org.opencontainer.image.vendor="Asif Bacchus <asif@asifbacchus.dev>"
# install mariadb and turn on TCP connection in default config # install mariadb and turn on TCP connection in default config
RUN apk --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main add \ RUN apk --no-cache --update add \
tzdata \ tzdata \
mariadb \ mariadb>${MARIADB_VERSION} \
mariadb-client \ mariadb-client>${MARIADB_VERSION} \
mariadb-server-utils \ mariadb-server-utils>${MARIADB_VERSION} \
&& rm -f /var/cache/apk/* \ && apk --no-cache --update upgrade \
&& sed -i 's/skip-networking/skip-networking=0/' /etc/my.cnf.d/mariadb-server.cnf && sed -i 's/skip-networking/skip-networking=0/' /etc/my.cnf.d/mariadb-server.cnf
# expose ports # expose ports
@@ -51,8 +58,13 @@ RUN mkdir -p /docker-entrypoint-preinit.d \
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ] ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]
CMD [ "/usr/bin/mysqld", "--user=mysql", "--console" ] CMD [ "/usr/bin/mysqld", "--user=mysql", "--console" ]
# add build date and version labels # set build timestamp and version labels
ARG INTERNAL_VERSION
ARG GIT_COMMIT
ARG BUILD_DATE ARG BUILD_DATE
LABEL org.label-schema.build-date=${BUILD_DATE} LABEL dev.asifbacchus.docker.internalVersion=${INTERNAL_VERSION}
LABEL org.label-schema.vendor="mariaDB (10.4.15-r0)" LABEL org.opencontainers.image.version="${INTERNAL_VERSION}-${MARIADB_VERSION}"
LABEL org.label-schema.version="1.0" LABEL org.opencontainers.image.revision=${GIT_COMMIT}
LABEL org.opencontainers.image.created=${BUILD_DATE}
#EOF
+26 -20
View File
@@ -1,6 +1,9 @@
# MariaDB on Alpine Linux (dockerized) # MariaDB on Alpine Linux (dockerized)
Fully functional dockerized installation of MariaDB server and client running on Alpine Linux. This container is roughly half the size of the official MariaDB container which runs on Ubuntu but still aims to mimic all its features while adding a few extra ;-) Fully functional dockerized installation of MariaDB server and client running on Alpine Linux. This container is roughly
half the size of the official MariaDB container which runs on Ubuntu but still aims to mimic all its features while
adding a few extra ;-) Note that this container is built against the Alpine EDGE repository for newer versions of
mariaDB.
- [Quick Start](#quick-start) - [Quick Start](#quick-start)
- [Pull the image](#pull-the-image) - [Pull the image](#pull-the-image)
@@ -37,11 +40,12 @@ Fully functional dockerized installation of MariaDB server and client running on
### Pull the image ### Pull the image
The latest images are on my private Docker Repo but I also try to keep the ones on Dockerhub updated within a few days. As such, you have two choices: The latest images are on my private docker registry but, I also try to keep the ones on Dockerhub updated within a few
days. If you need signed containers, you will have to use my private registry. As such, you have two choices:
```bash ```bash
# my private repo # my private repo
docker pull docker.asifbacchus.app/mariadb/ab-mariadb-alpine:latest docker pull asifbacchus/ab-mariadb-alpine:latest
``` ```
or or
@@ -51,7 +55,9 @@ or
docker pull asifbacchus/ab-mariadb-alpine:latest docker pull asifbacchus/ab-mariadb-alpine:latest
``` ```
All the examples in this document will refer to my repo, but you can use Dockerhub if you prefer. The examples in this document will refer to dockerhub, but know that anywhere you
see `asifbacchus/ab-mariadb-alpine:tag` you can use `docker.asifbacchus.app/mariadb/ab-mariadb-alpine` to use my
registry instead.
### Run the image ### Run the image
@@ -64,7 +70,7 @@ docker run -d \
-e MYSQL_DATABASE='CompanyX' \ -e MYSQL_DATABASE='CompanyX' \
-e MYSQL_USER='JaneDoe' \ -e MYSQL_USER='JaneDoe' \
-e MYSQL_PASSWORD='JanesPa$$w0rd' \ -e MYSQL_PASSWORD='JanesPa$$w0rd' \
docker.asifbacchus.app/mariadb/ab-mariadb-alpine asifbacchus/ab-mariadb-alpine
``` ```
Let's take a quick overview of the options used above: Let's take a quick overview of the options used above:
@@ -74,7 +80,7 @@ Let's take a quick overview of the options used above:
Assuming an existing database does not exist in the container's data directory already, it will create an empty database for you. The name of this database is controlled by the environment variable `MYSQL_DATABASE`. This defaults to 'myData'. If you would like to create a database called 'CompanyX', for example, you would set the environment variable as follows: Assuming an existing database does not exist in the container's data directory already, it will create an empty database for you. The name of this database is controlled by the environment variable `MYSQL_DATABASE`. This defaults to 'myData'. If you would like to create a database called 'CompanyX', for example, you would set the environment variable as follows:
```bash ```bash
docker run -d -e MYSQL_DATABASE='CompanyX' docker.asifbacchus.app/mariadb/ab-mariadb-alpine docker run -d -e MYSQL_DATABASE='CompanyX' asifbacchus/ab-mariadb-alpine
``` ```
#### Root password #### Root password
@@ -84,7 +90,7 @@ If you do not set a root password for mySQL, the container will generate one for
In normal usage, you will want to set the root password instead of having it generated for you. This is accomplished by setting the environment variable `MYSQL_ROOT_PASSWORD`. The command would look something like: In normal usage, you will want to set the root password instead of having it generated for you. This is accomplished by setting the environment variable `MYSQL_ROOT_PASSWORD`. The command would look something like:
```bash ```bash
docker run -d -e MYSQL_ROOT_PASSWORD='SuPeR$ecurEP@$$w0rd' docker.asifbacchus.app/mariadb/ab-mariadb-alpine docker run -d -e MYSQL_ROOT_PASSWORD='SuPeR$ecurEP@$$w0rd' asifbacchus/ab-mariadb-alpine
``` ```
#### User password #### User password
@@ -92,7 +98,7 @@ docker run -d -e MYSQL_ROOT_PASSWORD='SuPeR$ecurEP@$$w0rd' docker.asifbacchus.ap
If you would like a user account created for you with FULL privileges to the database created by the container, you must set two environment variables: `MYSQL_USER` and `MYSQL_PASSWORD`. You can do that as follows: If you would like a user account created for you with FULL privileges to the database created by the container, you must set two environment variables: `MYSQL_USER` and `MYSQL_PASSWORD`. You can do that as follows:
```bash ```bash
docker run -d -e MYSQL_USER='JaneDoe' -e MYSQL_PASSWORD='JanesPa$$w0rd' docker.asifbacchus.app/mariadb/ab-mariadb-alpine docker run -d -e MYSQL_USER='JaneDoe' -e MYSQL_PASSWORD='JanesPa$$w0rd' asifbacchus/ab-mariadb-alpine
``` ```
## Connecting as a client ## Connecting as a client
@@ -114,7 +120,7 @@ This will log you into the container using the root account and connect you to M
You can launch another instance of the container and use that as a client to connect to your server container or any other remote MariaDB/mySQL instance. In this case, we don't want to pass any environment variables, but we want to pass a separate CMD parameter as follows: You can launch another instance of the container and use that as a client to connect to your server container or any other remote MariaDB/mySQL instance. In this case, we don't want to pass any environment variables, but we want to pass a separate CMD parameter as follows:
```bash ```bash
docker run -it --rm docker.asifbacchus.app/mariadb/ab-mariadb-alpine mysql -hmysql.host.tld -uusername -ppassword docker run -it --rm asifbacchus/ab-mariadb-alpine mysql -hmysql.host.tld -uusername -ppassword
``` ```
**N.B.* I used the `--rm` Docker parameter to automatically remove the container on exit. This is optional. **N.B.* I used the `--rm` Docker parameter to automatically remove the container on exit. This is optional.
@@ -194,10 +200,10 @@ By default, the container will create a volume to store your mySQL database so y
```bash ```bash
# create a volume or use an existing named-volume # create a volume or use an existing named-volume
docker run -d -v mydatabase:/var/lib/mysql docker.asifbacchus.app/mariadb/ab-mariadb-alpine docker run -d -v mydatabase:/var/lib/mysql asifbacchus/ab-mariadb-alpine
# use a bind-mount location # use a bind-mount location
docker run -d -v /my/local/dir:/var/lib/mysql docker.asifbacchus.app/mariadb/ab-mariadb-alpine docker run -d -v /my/local/dir:/var/lib/mysql asifbacchus/ab-mariadb-alpine
``` ```
## Data instantiation/import ## Data instantiation/import
@@ -207,7 +213,7 @@ docker run -d -v /my/local/dir:/var/lib/mysql docker.asifbacchus.app/mariadb/ab-
The entrypoint script of the container simply checks to see if the */var/lib/mysql* directory is empty and, if so, creates a new database for you. Thus, if you want to import an existing database, you simply have to mount a valid *mysql* subdirectory: The entrypoint script of the container simply checks to see if the */var/lib/mysql* directory is empty and, if so, creates a new database for you. Thus, if you want to import an existing database, you simply have to mount a valid *mysql* subdirectory:
```bash ```bash
docker run -d -v /existing/mysql:/var/lib/mysql docker.asifbacchus.app/mariadb/ab-mariadb-alpine docker run -d -v /existing/mysql:/var/lib/mysql asifbacchus/ab-mariadb-alpine
``` ```
### Instantiation ### Instantiation
@@ -215,13 +221,13 @@ docker run -d -v /existing/mysql:/var/lib/mysql docker.asifbacchus.app/mariadb/a
If you want to 'instantiate' your newly created database (add tables, some default data, set privileges, etc.) then you can import SQL files with commands preloaded. Any *.sql* or *.sql.gz* files mounted in the container's */docker-entrypoint-initdb.d* folder will be imported after the new database is created. If you want to 'instantiate' your newly created database (add tables, some default data, set privileges, etc.) then you can import SQL files with commands preloaded. Any *.sql* or *.sql.gz* files mounted in the container's */docker-entrypoint-initdb.d* folder will be imported after the new database is created.
```bash ```bash
docker run -d -v /sql/import/scripts:/docker-entrypoint-initdb.d docker.asifbacchus.app/mariadb/ab-mariadb-alpine docker run -d -v /sql/import/scripts:/docker-entrypoint-initdb.d asifbacchus/ab-mariadb-alpine
``` ```
You should review the logs when doing this to see if MariaDB throws any errors due to syntax errors or other mistakes in your SQL files. An easy way to do this is: You should review the logs when doing this to see if MariaDB throws any errors due to syntax errors or other mistakes in your SQL files. An easy way to do this is:
```bash ```bash
docker run -d --name db -v /sql/import/scripts:/docker-entrypoint-initdb.d docker.asifbacchus.app/mariadb/ab-mariadb-alpine && docker logs -f db docker run -d --name db -v /sql/import/scripts:/docker-entrypoint-initdb.d asifbacchus/ab-mariadb-alpine && docker logs -f db
``` ```
You can, of course, name your container anything you like. Just change *'db'* in both places to whatever you choose. You can, of course, name your container anything you like. Just change *'db'* in both places to whatever you choose.
@@ -238,7 +244,7 @@ To run scripts after MariaDB is initialized (i.e. after a database is created an
docker run -d \ docker run -d \
-v /my/pre-init/scripts:/docker-entrypoint-preinit.d \ -v /my/pre-init/scripts:/docker-entrypoint-preinit.d \
-v /my/post-init/scripts:/docker-entrypoint-postinit.d \ -v /my/post-init/scripts:/docker-entrypoint-postinit.d \
docker.asifbacchus.app/mariadb/ab-mariadb-alpine asifbacchus/ab-mariadb-alpine
``` ```
### Entrypoint Task Order ### Entrypoint Task Order
@@ -267,7 +273,7 @@ For reference, the sequence of events in the entrypoint script is:
You can pass MariaDB command-line parameters to your container just as your would with a regular *mysqld* instance. For example: You can pass MariaDB command-line parameters to your container just as your would with a regular *mysqld* instance. For example:
```bash ```bash
docker run -d docker.asifbacchus.app/mariadb/ab-mariadb-alpine --innodb-ft-min-token-size=2 docker run -d asifbacchus/ab-mariadb-alpine --innodb-ft-min-token-size=2
``` ```
The container will concatenate any parameters your supply with the default ones of *--console --user=mysql*. Note that command-line parameters override environment variable parameters supplied to the container. The container will concatenate any parameters your supply with the default ones of *--console --user=mysql*. Note that command-line parameters override environment variable parameters supplied to the container.
@@ -280,12 +286,12 @@ If you would like to use a completely custom MariaDB configuration you will need
# custom my.cnf # custom my.cnf
docker run -d \ docker run -d \
-v /mysql/configuration/my.cnf:/etc/my.cnf \ -v /mysql/configuration/my.cnf:/etc/my.cnf \
docker.asifbacchus.app/mariadb/ab-mariadb-alpine asifbacchus/ab-mariadb-alpine
# custom server-related files # custom server-related files
docker run -d \ docker run -d \
-v /mysql/server-config:/etc/my.cnf.d \ -v /mysql/server-config:/etc/my.cnf.d \
docker.asifbacchus.app/mariadb/ab-mariadb-alpine asifbacchus/ab-mariadb-alpine
# complex configuration using custom my.cnf # complex configuration using custom my.cnf
# this completely depends on how you specify things in my.cnf # this completely depends on how you specify things in my.cnf
@@ -293,7 +299,7 @@ docker run -d \
-v /mysql/config/my.cnf:/etc/my.cnf \ -v /mysql/config/my.cnf:/etc/my.cnf \
-v /mysql/other-config:/etc/mysql/some-directory \ -v /mysql/other-config:/etc/mysql/some-directory \
-v /mysql/more-configs:/etc/mysql/cnf/another-dir \ -v /mysql/more-configs:/etc/mysql/cnf/another-dir \
docker.asifbacchus.app/mariadb/ab-mariadb-alpine asifbacchus/ab-mariadb-alpine
``` ```
You should be aware that the container passes *'--console --user=mysql'* command-line parameters to *mysqld* by default and that will override parameters specified in *my.cnf* or any other configuration file. If you need to override these defaults, you will have to pass the *mysqld* command manually: You should be aware that the container passes *'--console --user=mysql'* command-line parameters to *mysqld* by default and that will override parameters specified in *my.cnf* or any other configuration file. If you need to override these defaults, you will have to pass the *mysqld* command manually:
@@ -301,7 +307,7 @@ You should be aware that the container passes *'--console --user=mysql'* command
```bash ```bash
docker run -d \ docker run -d \
-v /mysql/configuration/my.cnf:/etc/my.cnf \ -v /mysql/configuration/my.cnf:/etc/my.cnf \
docker.asifbacchus.app/mariadb/ab-mariadb-alpine \ asifbacchus/ab-mariadb-alpine \
mysqld --user=anotheruser mysqld --user=anotheruser
``` ```
+5 -1
View File
@@ -19,6 +19,7 @@ isInt () {
# instantiate variables # instantiate variables
sqlCmd='/tmp/cmd.sql' sqlCmd='/tmp/cmd.sql'
showRootPassword=0
# convert env variables to uppercase for proper string comparison # convert env variables to uppercase for proper string comparison
MYSQL_SKIP_NAME_RESOLVE=$(convertCase "$MYSQL_SKIP_NAME_RESOLVE") MYSQL_SKIP_NAME_RESOLVE=$(convertCase "$MYSQL_SKIP_NAME_RESOLVE")
@@ -48,6 +49,7 @@ fi
if [ -z "$MYSQL_ROOT_PASSWORD" ]; then if [ -z "$MYSQL_ROOT_PASSWORD" ]; then
MYSQL_ROOT_PASSWORD="$( head /dev/urandom | tr -dc A-Za-z0-9 | head -c32 )" MYSQL_ROOT_PASSWORD="$( head /dev/urandom | tr -dc A-Za-z0-9 | head -c32 )"
export MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD export MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
showRootPassword=1
fi fi
# change mysql UID & GID # change mysql UID & GID
@@ -159,7 +161,9 @@ done
# note initialization complete and display root password # note initialization complete and display root password
printf "\nInitialization complete...\n" printf "\nInitialization complete...\n"
printf "(mySQL root password: %s)\n\n" "$MYSQL_ROOT_PASSWORD" if [ "$showRootPassword" -eq 1 ]; then
printf "(mySQL root password: %s)\n\n" "$MYSQL_ROOT_PASSWORD"
fi
# process CMD sent to this container # process CMD sent to this container
case "$1" in case "$1" in