2. Docker-搭建nginx mysql

  1. docker pull
>>  docker pull nginx:1.17.9
1.17.9: Pulling from library/nginx
123275d6e508: Pull complete 
9a5d769f04f8: Pull complete 
faad4f49180d: Pull complete 
Digest: sha256:88ea86df324b03b3205cbf4ca0d999143656d0a3394675630e55e49044d38b50
Status: Downloaded newer image for nginx:1.17.9
docker.io/library/nginx:1.17.9
  1. docke run
>> docker run -d  --name nginx -p 8080:80 nginx:1.17.9  
//nginx:1.17.9  (同上面pull的Status: Downloaded newer image for nginx:1.17.9
docker.io/library/nginx:1.17.9)-d 后天运行哦
bd002733203d169f691eacfcd183af7e4132efafb2c9d52d560ff4a844f25bb3
http://localhost:8080/
  1. docker ps 看进程
>> docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                  NAMES
bd002733203d   nginx:1.17.9   "nginx -g 'daemon of…"   7 minutes ago   Up 7 minutes   0.0.0.0:8080->80/tcp   nginx
  1. docker rm 删除容器
>>> docker rm nginx
Error response from daemon: You cannot remove a running container bd002733203d169f691eacfcd183af7e4132efafb2c9d52d560ff4a844f25bb3. Stop the container before attempting removal or force remove

docker rm -f 容器 强制删除

  1. docker stop 停止容器
    docker stop nginx
  2. docker run 设置挂载目录 防止误操作影响了服务
docker run -d  --name nginx -p 8080:80 -v ./nginx/html:/usr/share/nginx/html nginx:1.17.9  

docker pull mysql:8.0.26

docker run -d --name mysql -p 3307:3307 --privileged=true -e MYSQL_ROOT_PASSWORD=123456 mysql:8.0.26

端口3306被占用

sudo lsof -i:3306
看是不是本地装了一个mysql 并配置了开机启动项

docker  exec -it mysql bash //进入mysql
mysql -u root -p 
password:123456
alter user 'admin'@'localhost' identified by '123456'. //增加 用户
create database my_data
show databases
drop databases mydata
use mydata  
select version()
select now()
ahahh

你可能感兴趣的:(2. Docker-搭建nginx mysql)