Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Docker Compose MySQL server

version: '3.8'
services:
  client:
    build: .
    volumes:
    - .:/opt
    links:
    - mysql
    command: tail -f /dev/null
  mysql:
    image: mysql:latest
    environment:
      MYSQL_ROOT_PASSWORD: secret

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

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