Forcus on mysql container.
pull image
docker pull mysql
build and run container from pulling image
docker run --name port_sql_test -e MYSQL_ROOT_PASSWORD=mysql -d mysql:latest
show running contaner
If you want to show all container even not working containers set an argument -a
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aa7e4caddcac mysql:latest "docker-entrypoint.s…" 22 minutes ago Exited (0) 19 minutes ago port_sql_test
850282fc85bf sail-8.2/app "start-container" 2 months ago Exited (255) 33 minutes ago 0.0.0.0:80->80/tcp, 0.0.0.0:5173->5173/tcp, 8000/tcp example-app-laravel.test-1
d5d94fd21974 mysql/mysql-server:8.0 "/entrypoint.sh mysq…" 2 months ago Exited (255) 33 minutes ago 0.0.0.0:3306->3306/tcp, 33060-33061/tcp example-app-mysql-1
ff22638b1203 seleniarm/standalone-chromium "/opt/bin/entry_poin…" 2 months ago Exited (255) 33 minutes ago 4444/tcp, 5900/tcp example-app-selenium-1
fc7c506832b1 redis:alpine "docker-entrypoint.s…" 2 months ago Exited (255) 33 minutes ago 0.0.0.0:6379->6379/tcp example-app-redis-1
8a3ae3073074 getmeili/meilisearch:latest "tini -- /bin/sh -c …" 2 months ago Exited (255) 33 minutes ago 0.0.0.0:7700->7700/tcp example-app-meilisearch-1
67777ccb4f55 axllent/mailpit:latest "/mailpit" 2 months ago Exited (255) 33 minutes ago 0.0.0.0:1025->1025/tcp, 0.0.0.0:8025->8025/tcp example-app-mailpit-1
393ed61d795f mysql/mysql-server:8.0 "/entrypoint.sh mysq…" 2 months ago Exited (255) 33 minutes ago 3306/tcp, 33060-33061/tcp example-app-mysql.test-1
8edd08a70f89 nginx:latest "/docker-entrypoint.…" 6 months ago Exited (255) 6 months ago 80/tcp, 0.0.0.0:8000->8080/tcp nginx00
0b026e8fe77d zabbix/zabbix-appliance:latest "/sbin/tini -- /usr/…" 7 months ago Exited (255) 7 months ago 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:10051->10051/tcp zabbix-appliance
9274db4e267a debian "bash" 8 months ago Exited (1) 8 months ago zealous_gates
stop container
docker stop {CONTAINER ID}
docker-compose
example directory structure
├── docker-compose.yml
└── mysql
├── DB
│ └── world.sql
├── Dockerfile
└── my.cnf
※1 You can get world .sql from here.
mysql.cnf
[mysqld]
character-set-server=utf8
[mysql]
default-character-set=utf8
[client]
default-character-set=utf8
start docker-compose process
-d
is an optional argument which executes as deamon process, but executing as deamon process is normal.
docker-compose up -d
stop docker-compose
docker-compose stop
docker-compose.yml
version: "3"
services:
mysql:
# It indicate that this system is built by Dockerfile
build: ./mysql
volumes:
# The place which mounts initial data
- ./mysql/DB:/docker-entrypoint-init.d
# Image name
image: original_mysql_world
ports:
- 3306:3306
environment:
# Setting password when launching MySQL in the container
- MYSQL_ROOT_PASSWORD=mysql
- MYSQL_ROOT_HOSTS=%
Dockerfile
※You have to name Dockerfile to Dockerfile
(no ohter names without exceptions)
# Docker Image for using
FROM mysql
# Open port
EXPOSE 3306
# Copy configuration file in the image
ADD ./my.cnf /etc/mysql/conf.d/my.cnf
# Executed when executing `docker run`
CMD ["mysqld"]
コメント