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
復(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.訪問nginx

以上就是docker部署mysql和nginx服務(wù)的示例詳解的詳細內(nèi)容,更多關(guān)于docker部署mysql和nginx的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Docker鏡像構(gòu)建之docker commit的使用
本文主要介紹了Docker鏡像構(gòu)建之docker commit的使用,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04
docker安裝redis(鏡像安裝)的實現(xiàn)示例
這篇文章主要介紹了docker安裝redis(鏡像安裝)的實現(xiàn)示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考,一起跟隨小編過來看看吧2019-02-02
Docker容器中Kingbase數(shù)據(jù)庫授權(quán)到期更換的解決方案
當(dāng)Docker容器內(nèi)的Kingbase數(shù)據(jù)庫授權(quán)文件(license.dat)到期后,會直接導(dǎo)致數(shù)據(jù)庫無法啟動、核心功能受限,本文結(jié)合官方鏡像特性與實操經(jīng)驗,整理了一套完整、可直接落地的授權(quán)更換與數(shù)據(jù)庫恢復(fù)方案,需要的朋友可以參考下2026-04-04
docker?registry刪除遠程倉庫鏡像實現(xiàn)方式
文章介紹如何清理Docker?Registry中堆積的鏡像,通過配置刪除功能、啟動容器、查看鏡像信息并執(zhí)行刪除操作,同時提供基于web-ui的管理方案,優(yōu)化存儲空間使用2025-09-09
Jenkins Docker靜態(tài)agent節(jié)點的構(gòu)建過程
這篇文章主要介紹了Jenkins Docker靜態(tài)agent節(jié)點的構(gòu)建,靜態(tài)節(jié)點就是通過java -jar這條命令去啟動起來就可以了,本文通過圖文實例相結(jié)合給大家介紹的非常詳細,需要的朋友可以參考下2021-10-10
Docker學(xué)習(xí)之搭建ActiveMQ消息服務(wù)的方法步驟
這篇文章主要介紹了Docker學(xué)習(xí)之搭建ActiveMQ消息服務(wù)的方法步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09

