docker部署mysql和nginx服務(wù)的示例詳解
mysql
Centos7為例
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
1.安裝docker環(huán)境
聯(lián)網(wǎng)環(huán)境在線yum
yum update yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install -y docker-ce docker-ce-cli containerd.io systemctl start docker systemctl enable docker
2.search下mysql鏡像
3.下載一個(gè)5.7的鏡像,默認(rèn)為latest
docker pull mysql:5.7
4.創(chuàng)建mysql容器
使用mysql:5.7的鏡像創(chuàng)建一個(gè)名字為mysql-container的容器,并設(shè)置了mysql的root密碼的環(huán)境變量及映射端口為3306
docker run -d --name mysql-container -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 mysql:5.7
- -d: 指定容器應(yīng)該在后臺(tái)運(yùn)行。
- -it: 讓容器能夠與終端進(jìn)行交互。
- –name: 指定容器的名稱。
- -p: 將容器端口映射到主機(jī)上的端口。
- -v: 指定卷并將其掛載到容器中。
5.查看容器進(jìn)程
docker ps | grep mysql
6.進(jìn)入容器
docker exec -it mysql-container /bin/bash
7.創(chuàng)建數(shù)據(jù)庫(kù)及表
create database docker use docker create table DockerImages(images_id int not null primary key, images_name varchar(20), create_time TIMESTAMP); insert into DockerImages(id,images_name,create_time)values('1','mysql','2023-10-17 16:00:00');
8.退出容器,在宿主機(jī)上執(zhí)行命令測(cè)試
9.使用Navicat連接mysql測(cè)試
nginx
1.先下載鏡像
docker pull nginx
2.宿主機(jī)上創(chuàng)建index.html
mkdir -p /usr/share/nginx/html/index.html
復(fù)制如下內(nèi)容:
<!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>hahahhahahahaha</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to .<br/> Commercial support is available at .</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
3.創(chuàng)建容器
docker run --name mynginx -p 8080:80 -v /usr/share/nginx/html/index.html:/usr/share/nginx/html/index.html -d nginx:latest
映射目錄是為了數(shù)據(jù)持久化,否則容器內(nèi)修改的任何數(shù)據(jù)在重啟容器后,數(shù)據(jù)將恢復(fù)原樣
4.修改title
5.重啟nginx容器
docker restart mynginx
6.訪問(wèn)nginx
以上就是docker部署mysql和nginx服務(wù)的示例詳解的詳細(xì)內(nèi)容,更多關(guān)于docker部署mysql和nginx的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- Python基于docker部署的Mysql備份查詢腳本
- docker-compose部署mysql數(shù)據(jù)庫(kù)完整步驟
- docker部署的mysql默認(rèn)密碼如何查看
- Docker?中?MySQL?的部署與管理技巧
- 使用Docker部署MySQL數(shù)據(jù)庫(kù)的兩種方法
- 使用Docker部署的基于binlog實(shí)現(xiàn)Mysql8的操作方法
- 在Ubuntu下通過(guò)Docker部署MySQL服務(wù)器的詳細(xì)步驟
- 使用Docker容器在Linux上部署MySQL方式
- docker部署mysql?9.0.1的實(shí)現(xiàn)
相關(guān)文章
Docker跨服務(wù)器通信Overlay解決方案(上)之 Consul單實(shí)例
這篇文章主要介紹了Docker跨服務(wù)器通信Overlay解決方案(上)之 Consul單實(shí)例,本文通過(guò)場(chǎng)景分析實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-12-12docker registry安裝簡(jiǎn)單命令實(shí)現(xiàn)
這篇文章主要介紹了docker registry安裝詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2016-10-10基于Docker與Jenkins實(shí)現(xiàn)自動(dòng)化部署的原理解析
這篇文章主要介紹了基于Docker與Jenkins實(shí)現(xiàn)自動(dòng)化部署,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04Docker與iptables及實(shí)現(xiàn)bridge方式網(wǎng)絡(luò)隔離與通信操作
這篇文章主要介紹了Docker與iptables及實(shí)現(xiàn)bridge方式網(wǎng)絡(luò)隔離與通信操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11mysql8.4.0實(shí)現(xiàn)主從復(fù)制部署
主從復(fù)制是 MySQL 中一種用于實(shí)現(xiàn)數(shù)據(jù)冗余、提高可用性和性能的重要機(jī)制,本文主要介紹了mysql8.4.0實(shí)現(xiàn)主從復(fù)制部署,具有一定的參考價(jià)值,感興趣的可以了解一下2024-07-07docker-compose java.net.UnknownHostException問(wèn)題
這篇文章主要介紹了docker-compose java.net.UnknownHostException問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05