5/30 TIL: mysql Docker image, Unix Domain Socket
David Hwang
Posted on May 31, 2021
Docker Compose
- Do a 'docker-compose -f nameOfYourDockerComposeFile build' if you need your changes in Dockerfile to be reflected—because simply doing 'docker-compose up' doesn't rebuild an image
Docker mysql image
- Configuration options can be passed as flags in the command line. Ex) --character-set-server=utf8mb4
- When a mysql container is started for the first time, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. So we can populate our mysql services by mounting a SQL dump into that directory. In our example below, we would store our .sql files in db/init and mount it to /docker-entrypoint-initdb.d under volumes:
services:
db:
container_name: mysql
image: mysql
restart: always
environment:
MYSQL_USER: user1
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
MYSQL_DATABASE: users
ports:
- '3306:3306'
volumes:
- mysql_db:/var/lib/mysql
- ./db/init:/docker-entrypoint-initdb.d
command:
[
'mysqld',
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_unicode_ci',
]
volumes:
mysql_db:
Unix Domain Socket
- an inter-process communication mechanism that allows bidirectional data exchange between processes on the "same" machine—faster and lighter than IP sockets because it skips checks and operations like routing
- vs. IP sockets: a mechanism allowing communication between processes over the network
- https://serverfault.com/questions/124517/what-is-the-difference-between-unix-sockets-and-tcp-ip-sockets
- blog post: https://medium.com/swlh/getting-started-with-unix-domain-sockets-4472c0db4eb1
💖 💪 🙅 🚩
David Hwang
Posted on May 31, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.