From 39711ee37497635e7d35fbe36aee6ee31efbaa94 Mon Sep 17 00:00:00 2001 From: Gabor Szabo Date: Thu, 4 May 2023 10:08:19 +0300 Subject: [PATCH] add mysql example; fix postgresql example --- docker/compose.md | 37 +++++++++++++++++-- docker/examples/mysql/Dockerfile | 7 ++++ docker/examples/mysql/docker-compose.yml | 14 +++++++ docker/examples/postgresql/Dockerfile | 2 +- docker/examples/postgresql/docker-compose.yml | 4 +- 5 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 docker/examples/mysql/Dockerfile create mode 100644 docker/examples/mysql/docker-compose.yml diff --git a/docker/compose.md b/docker/compose.md index ac87e1215..6b14fc327 100644 --- a/docker/compose.md +++ b/docker/compose.md @@ -235,7 +235,7 @@ In one container start the Docker server, the other one will be the client that ![](examples/postgresql/docker-compose.yml) -The Dockerfile is also based on the official mongodb image as that made it easy to have `mongosh` already installed. +The Dockerfile is built on top of a plain Ubuntu image ![](examples/postgresql/Dockerfile) @@ -248,12 +248,12 @@ docker-compose up -d Connect to the client container: ``` -docker exec -it mongodb_client_1 bash +$ docker exec -it postgresql_client_1 bash ``` ``` -psql -h postgres --username username -d mydb +# psql -h postgres --username username -d mydb ``` It will ask for a password: @@ -274,7 +274,7 @@ Type "help" for help. mydb=# ``` -Alternativel, once inside the clien docker container we can put the variable of the database in an environment variable and then we can run a command that will not wait for any input. +Alternativel, once inside the client docker container we can put the variable of the database in an environment variable and then we can run a command that will not wait for any input. ``` export PGPASSWORD=password @@ -325,5 +325,34 @@ And you can also generate test coverage report: cover -test ``` +## Docker Compose MySQL server +{id: docker-compose-mysql-server} + +![](examples/mysql/docker-compose.yml) +![](examples/mysql/Dockerfile) + +``` +docker-compose up -d +``` + + +``` +docker exec -it mysql_client_1 bash +``` + +``` +ping mysql +``` + + +``` +# mysql -h mysql --password=secret +mysql> SELECT CURRENT_TIMESTAMP; +mysql> exit +``` + +``` +# echo "SELECT CURRENT_TIMESTAMP" | mysql -h mysql --password=secret +``` diff --git a/docker/examples/mysql/Dockerfile b/docker/examples/mysql/Dockerfile new file mode 100644 index 000000000..0a46526df --- /dev/null +++ b/docker/examples/mysql/Dockerfile @@ -0,0 +1,7 @@ +FROM ubuntu:22.04 +RUN apt-get update && \ + apt-get install -y curl && \ + apt-get install -y inetutils-ping && \ + apt-get install -y mysql-client && \ + echo DONE + diff --git a/docker/examples/mysql/docker-compose.yml b/docker/examples/mysql/docker-compose.yml new file mode 100644 index 000000000..4facadb8c --- /dev/null +++ b/docker/examples/mysql/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3.8' +services: + client: + build: . + volumes: + - .:/opt + links: + - mysql + command: tail -f /dev/null + mysql: + image: mysql:latest + environment: + MYSQL_ROOT_PASSWORD: secret + diff --git a/docker/examples/postgresql/Dockerfile b/docker/examples/postgresql/Dockerfile index 821c58f03..5ada62dcc 100644 --- a/docker/examples/postgresql/Dockerfile +++ b/docker/examples/postgresql/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:22.04 +FROM ubuntu:23.04 RUN apt-get update && \ apt-get install -y curl && \ apt-get install -y inetutils-ping && \ diff --git a/docker/examples/postgresql/docker-compose.yml b/docker/examples/postgresql/docker-compose.yml index 3ab66831b..c02c5fe4e 100644 --- a/docker/examples/postgresql/docker-compose.yml +++ b/docker/examples/postgresql/docker-compose.yml @@ -14,7 +14,7 @@ services: POSTGRES_PASSWORD: password POSTGRES_DB: mydb volumes: - - database-data:/var/lib/postgresql/data/ + - postgres-database-data:/var/lib/postgresql/data/ volumes: - database-data: + postgres-database-data: