Skip to content

Commit

Permalink
add mysql example; fix postgresql example
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed May 4, 2023
1 parent 4dbb23c commit 39711ee
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
37 changes: 33 additions & 4 deletions docker/compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
```

7 changes: 7 additions & 0 deletions docker/examples/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

14 changes: 14 additions & 0 deletions docker/examples/mysql/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion docker/examples/postgresql/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 && \
Expand Down
4 changes: 2 additions & 2 deletions docker/examples/postgresql/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

0 comments on commit 39711ee

Please sign in to comment.