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)文章!
相關(guān)文章
Docker部署及使用壓測(cè)神器sysbench的方法
sysbench 是一個(gè)開源跨平臺(tái)的多線程性能測(cè)試工具,這篇文章主要介紹了Docker部署及使用壓測(cè)神器sysbench的相關(guān)知識(shí),需要的朋友可以參考下2022-08-08
Docker容器互相連接三種實(shí)現(xiàn)方法詳解
這篇文章主要介紹了Docker容器互連三種實(shí)現(xiàn)方法詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05
Docker鏡像構(gòu)建速度優(yōu)化實(shí)現(xiàn)
本文主要介紹了Docker鏡像構(gòu)建速度優(yōu)化實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-12-12
docker環(huán)境調(diào)用mysqldump進(jìn)行數(shù)據(jù)備份方式
這篇文章主要介紹了docker環(huán)境調(diào)用mysqldump進(jìn)行數(shù)據(jù)備份方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-06-06
通過(guò)Docker運(yùn)行AnythingLLM的方法
這篇文章主要介紹了通過(guò)Docker運(yùn)行AnythingLLM的方法,本文給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧2024-12-12
docker搭建xxl-job的實(shí)現(xiàn)步驟
XXL-JOB是一個(gè)輕量級(jí)分布式任務(wù)調(diào)度平臺(tái),通過(guò)xxljob,我們可以方便地實(shí)現(xiàn)任務(wù)調(diào)度和任務(wù)執(zhí)行監(jiān)控,本文介紹了docker搭建xxl-job的實(shí)現(xiàn)步驟,感興趣的可以了解一下2023-12-12
CentOS7 Nvidia Docker環(huán)境搭建
本篇文章主要介紹了CentOS7 Nvidia Docker環(huán)境搭建,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-02-02

