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.下載一個5.7的鏡像,默認為latest
docker pull mysql:5.7
4.創(chuàng)建mysql容器
使用mysql:5.7的鏡像創(chuàng)建一個名字為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)該在后臺運行。
- -it: 讓容器能夠與終端進行交互。
- –name: 指定容器的名稱。
- -p: 將容器端口映射到主機上的端口。
- -v: 指定卷并將其掛載到容器中。
5.查看容器進程
docker ps | grep mysql
6.進入容器
docker exec -it mysql-container /bin/bash
7.創(chuàng)建數(shù)據(jù)庫及表
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.退出容器,在宿主機上執(zhí)行命令測試
9.使用Navicat連接mysql測試
nginx
1.先下載鏡像
docker pull nginx
2.宿主機上創(chuàng)建index.html
mkdir -p /usr/share/nginx/html/index.html
復制如下內(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ù)將恢復原樣
4.修改title
5.重啟nginx容器
docker restart mynginx
6.訪問nginx
以上就是docker部署mysql和nginx服務(wù)的示例詳解的詳細內(nèi)容,更多關(guān)于docker部署mysql和nginx的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Docker鏡像構(gòu)建速度優(yōu)化實現(xiàn)
本文主要介紹了Docker鏡像構(gòu)建速度優(yōu)化實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2024-12-12docker環(huán)境調(diào)用mysqldump進行數(shù)據(jù)備份方式
這篇文章主要介紹了docker環(huán)境調(diào)用mysqldump進行數(shù)據(jù)備份方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2025-06-06CentOS7 Nvidia Docker環(huán)境搭建
本篇文章主要介紹了CentOS7 Nvidia Docker環(huán)境搭建,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-02-02