---
# System prepended metadata

title: 設定 Jupyter Lab

---

# 設定 Jupyter Lab
##### tags: `tutorials` `PairLab`

## 進入 container
```shell
$ ssh pairlab@140.113.110.xx 
$ sudo docker ps -a # 看自己container的名字
$ sudo docker start [name]
$ sudo docker ps # 看自己container的port
$ ssh root@140.113.110.xx -p [對應22的port] # 進入container，密碼12345678
```

## 設定 Jupyter Lab 檔案 (in container)
```shell
$ cd ~
$ vim .jupyter.sh
```
將以下輸入
```shell
jupyter lab --allow-root --ip=0.0.0.0
```
更改 .jupyter.sh 權限
```shell
$ sudo chmod +x .jupyter.sh
```
設定 Jupter Lab 密碼
```shell
$ jupyter notebook password
```

## 回到主機開 Jupyter Lab
```shell
# [name] 改成 container 的名字
sudo docker start [name] # 若是已開了就不用再執行
sudo docker exec -d [name] /bin/bash /root/.jupyter.sh # 執行 Jupyter Lab
```


# 開機自動開啟container與jupyterlab

### /home/pairlab/jupyter.sh
chmod 777
```shell=
sudo docker start $1
sudo docker exec -d $1 /bin/bash /root/.jupyter.sh
```

### /home/pairlab/startup.sh
chmod 777
```shell=
#!/bin/sh

/home/pairlab/jupyter.sh [container name]
/home/pairlab/jupyter.sh [container name]
```

### /etc/systemd/system/start-container.service
```shell=
[Unit]
Description=Start Container, executive /home/startup.sh.

[Service]
ExecStart=/home/pairlab/startup.sh

[Install]
WantedBy=multi-user.target
```

```shell=
sudo systemctl enable start-container.service
```
