docker-compose MySQL

[root@169_test mariadb10.3]# cat docker-compose.yml
version: '2'

services:
db:
image: mytest/mariadb10.3:latest
volumes:

  - ./db_data/:/var/lib/mysql/
restart: always
ports:
  - "3306:3306"

[root@169_test mariadb10.3]# docker-compose up
Creating network "mariadb103_default" with the default driver
Creating mariadb103_db_1 ... done
Attaching to mariadb103_db_1
db_1 | Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
db_1 | OK
db_1 |
db_1 | To start mysqld at boot time you have to copy
db_1 | support-files/mysql.server to the right place for your system
db_1 |
db_1 |
db_1 | PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
db_1 | To do so, start the server, then issue the following commands:
db_1 |
db_1 | '/usr/bin/mysqladmin' -u root password 'new-password'
db_1 | '/usr/bin/mysqladmin' -u root -h d56fe1b27eb9 password 'new-password'
db_1 |
db_1 | Alternatively you can run:
db_1 | '/usr/bin/mysql_secure_installation'
db_1 |
db_1 | which will also give you the option of removing the test
db_1 | databases and anonymous user created by default. This is
db_1 | strongly recommended for production servers.
db_1 |
db_1 | See the MariaDB Knowledgebase at http://mariadb.com/kb or the
db_1 | MySQL manual for more instructions.
db_1 |
db_1 | You can start the MariaDB daemon with:
db_1 | cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'
db_1 |
db_1 | You can test the MariaDB daemon with mysql-test-run.pl
db_1 | cd '/usr/mysql-test' ; perl mysql-test-run.pl
db_1 |
db_1 | Please report any problems at http://mariadb.org/jira
db_1 |
db_1 | The latest information about MariaDB is available at http://mariadb.org/.
db_1 | You can find additional information about the MySQL part at:
db_1 | http://dev.mysql.com
db_1 | Consider joining MariaDB's strong and vibrant community:
db_1 | https://mariadb.org/get-involved/
db_1 |
db_1 | Starting MariaDB.190611 03:38:08 mysqld_safe Logging to '/var/lib/mysql/d56fe1b27eb9.err'.
db_1 | 190611 03:38:08 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
db_1 | SUCCESS!

^CGracefully stopping... (press Ctrl+C again to force)
Stopping mariadb103_db_1 ...
Killing mariadb103_db_1 ... done
[root@169_test mariadb10.3]# ^C
[root@169_test mariadb10.3]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d56fe1b27eb9 mytest/mariadb10.3:latest "/run.sh" 27 seconds ago Exited (137) 7 seconds ago mariadb103_db_1
762ed1f53368 registry:2 "/entrypoint.sh /etc…" 2 hours ago Up 2 hours 0.0.0.0:5000->5000/tcp registry
[root@169_test mariadb10.3]# docker rm d
d
[root@169_test mariadb10.3]# docker-compose up -d
Creating mariadb103_db_1 ... done

[root@169_test mariadb10.3]# mysql -h127.0.0.1 -uroot -P3306 -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.5.5-10.3.15-MariaDB MariaDB Server

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select @@version;
+-----------------+
| @@version |
+-----------------+
| 10.3.15-MariaDB |
+-----------------+
1 row in set (0.00 sec)

mysql>

转载于:https://blog.51cto.com/860143/2407183

通过提供的引用内容,可以看出用户想了解关于使用docker-compose部署mysql容器的问题。 要使用docker-compose启动mysql容器,需要创建一个docker-compose.yml文件,其中包含mysql服务的配置。在该文件中,可以指定mysql的镜像版本、容器名称、环境变量、端口映射和数据卷等。根据引用中的示例,以下是一个docker-compose.yml文件的示例配置: ```yaml version: '3' services: mysql: image: mysql:5.7 restart: always container_name: mysql environment: MYSQL_ROOT_PASSWORD: chen command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true --lower_case_table_names=1 --max_allowed_packet=128M ports: - 3306:3306 volumes: - /data/mysql:/var/lib/mysql - /etc/localtime:/etc/localtime:ro ``` 在该示例中,使用了mysql:5.7的镜像版本,并指定了容器的名称为mysql。通过environment字段,可以设置mysql的root密码。ports字段指定了宿主机和容器之间的端口映射关系,将宿主机的3306端口映射到容器的3306端口。volumes字段指定了数据卷的映射关系,将宿主机的/data/mysql目录映射到容器的/var/lib/mysql目录。 要启动并运行整个应用程序,可以使用docker-compose的up命令。根据引用的示例,以下是启动docker-compose服务的命令: ```bash docker-compose up ``` 这将会启动所有配置在docker-compose.yml文件中的服务。如果希望在后台运行服务,可以使用docker-compose up -d命令。 至此,您已经成功使用docker-compose部署了mysql容器。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [docker compose 安装Mysql](https://blog.csdn.net/cjj2006/article/details/129246910)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [docker-compose(部署微服务+MySQL)](https://blog.csdn.net/weixin_38380811/article/details/127853696)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值