# 安装必要的工具
apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
# 添加GPG密钥(使用 apt-key fingerprint 进行验证)(0EBFCD88)
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# 设置存储库
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
# 安装Docker-CE和containerd
apt-get install docker-ce docker-ce-cli containerd.io
# 拉取镜像并启动容器
docker run -d -p 8080:80 --rm --name mynginx nginx
# 新建目录(/home/tzx)
mkdir nginx
# 从容器内部拷贝出配置文件
docker cp mynginx:/etc/nginx .
# 修改目录名称(目前目录层级结构为:/home/tzx/nginx/conf)
mv nginx conf
# "cd conf" 后修改配置文件nginx.conf,在http下新增如下内容:
# 192.168.23.141为nginx宿主机ip
# 192.168.23.146为jupyter lab的宿主机ip
server {
listen 8080;
server_name 192.168.23.141;
location /tzx {
proxy_pass http://192.168.23.146:10001;
proxy_set_header Host $host;
proxy_set_header X-Real-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 120s;
proxy_next_upstream error;
# port_in_redirect on;
}
location /lyy {
proxy_pass http://192.168.23.146:10002;
proxy_set_header Host $host;
proxy_set_header X-Real-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 120s;
proxy_next_upstream error;
}
}
# 停止容器并重新启动
docker stop mynginx
docker container run --rm --name mynginx --volume "/home/tzx/nginx/conf":/etc/nginx -p 8080:8080 -d nginx
使用上节中的镜像,修改镜像中的配置,并启动两个Jupyter Lab实例。
# 启动容器tzx,并进入内部
docker run -p 10001:8888 -v /root/data/lab1:/tzx --cpus 1 -m 2G -it centos7:v2 bash
# 新增配置属性(/root/.jupyter/jupyter_notebook_config.py)
c.NotebookApp.allow_root = True
c.NotebookApp.open_browser = False
c.NotebookApp.ip = '*'
c.NotebookApp.base_url = '/tzx'
# 内部启动jupyter lab
jupyter lab
-----------------------------------------------
# 启动容器lyy,并进入内部
docker run -p 10002:8888 -v /root/data/lab1:/tzx --cpus 1 -m 2G -it centos7:v2 bash
# 新增配置属性(/root/.jupyter/jupyter_notebook_config.py)
c.NotebookApp.allow_root = True
c.NotebookApp.open_browser = False
c.NotebookApp.ip = '*'
c.NotebookApp.base_url = '/lyy'
# 内部启动jupyter lab
jupyter lab
使用 http://192.168.23.149:8080/tzx 和 http://192.168.23.149:8080/lyy 即可进入到不同的jupyter lab实例中。