task2
apache:
docker run -d -v ~/www/:/usr/local/apache2/htdocs/ -p 80:80 httpd
mysql:5.7
docker run -d -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=1qaz@WSX mysql:5.7
远程登录:
mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@‘%’ IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
MYSQL_ROOT_PASSWORD
安装:
前提条件
目前,CentOS 仅发行版本中的内核支持 Docker。Docker 运行在CentOS 7 (64-bit)上,
要求系统为64位、Linux系统内核版本为 3.8以上,这里选用Centos7.x
确定你是CentOS7及以上版本
cat /etc/redhat-release
- yum安装gcc相关
yum -y install gcc yum -y install gcc-c++
3.安装需要的软件包
yum install -y yum-utils
4.设置stable镜像仓库,这里用阿里的,官网上的有时候会超时
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
5.更新yum软件包索引(推荐执行)
yum makecache fast
6.安装DOCKER CE
yum -y install docker-ce docker-ce-cli containerd.io
7.启动docker
systemctl start docker
8.测试
docker version docker run hello-world
9.卸载
systemctl stop docker yum remove docker-ce docker-ce-cli containerd.io rm -rf /var/lib/docker rm -rf /var/lib/containerd
阿里云镜像加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://hub-mirror.c.163.com/"]
}
EOF
重启服务器:
systemctl daemon-reload
systemctl restart docker
nginx 反向代理
1. 创建目录
- `mkdir -p /usr/share/nginx/conf
`
- `mkdir -p /usr/share/nginx/html
`
2. 创建配置文件
- `touch /usr/share/nginx/conf/nginx.conf
`
在nginx.conf文件添加如下配置
worker_processes 1;
- `events {
`
worker_connections 1024;
}
- `http {
`
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
# 代理转发请求至网关,prod-api标识解决跨域问题
location /prod-api/ {
proxy_pass http://www.youlai.store:9999/;
}
}
}
3. 拉取镜像
- `docker pull nginx
`
查看镜像
- `docker images
`
4. 创建容器并启动
- `docker run -it -d \
`
- `--name nginx \
`
- `-p 80:80 \
`
- `-v /usr/share/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
`
- `-v /usr/share/nginx/html:/usr/share/nginx/html \
`
- `nginx
`
两个-v 分别表示配置文件和nginx工作空间目录的映射,冒号左边是宿主机,右边是容器的,这样修改宿主机的配置文件和工作空间就可以同步到容器
5. 查看容器
- `docker ps -a
`
6. 查看nginx启动日志
- `docker logs nginx
`
7. 启动、关闭、重启nginx
- `docker start nginx
`
- `docker stop nginx
`
- `docker restart nginx
`
jar
FROM java:8
MAINTAINER xx
ADD user-0.0.1-SNAPSHOT.jar user.jar
EXPOSE 8001
ENTRYPOINT ["java","-jar","user.jar"]