目录
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"
联网环境在线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
docker pull mysql:5.7
使用mysql:5.7的镜像创建一个名字为mysql-container的容器,并设置了mysql的root密码的环境变量及映射端口为3306
docker run -d --name mysql-container -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 mysql:5.7
- -d: 指定容器应该在后台运行。
- -it: 让容器能够与终端进行交互。
- –name: 指定容器的名称。
- -p: 将容器端口映射到主机上的端口。
- -v: 指定卷并将其挂载到容器中。
docker ps | grep mysql
docker exec -it mysql-container /bin/bash
- 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');
docker pull nginx
- mkdir -p /usr/share/nginx/html/index.html
-
- 复制如下内容:
-
-
- <!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>
docker run --name mynginx -p 8080:80 -v /usr/share/nginx/html/index.html:/usr/share/nginx/html/index.html -d nginx:latest
映射目录是为了数据持久化,否则容器内修改的任何数据在重启容器后,数据将恢复原样
docker restart mynginx