eustomaqua / eustomaqua.github.io

Personal Homepage: https://eustomaqua.github.io/
0 stars 0 forks source link

Docker 使用尝试 #3

Open eustomaqua opened 6 months ago

eustomaqua commented 6 months ago

Docker images 安装 本地机 (Win 11)

$ docker pull continuumio/anaconda3
$ docker pull continuumio/miniconda3
$ docker pull ubuntu
$ docker cp Downloads/Anaconda3-2023.03-Linux-x86_64.sh <container-id>:/home/
$ docker cp GitHubLab/ResearchWork <container-id>:/home/

镜像环境

# cd /home/   # or /root/
# bash ./Aanconda3-2023.03-Linux-x86_64.sh
# apt update
# apt install vim
# apt install wget
# vim ~/.bashrc
# source ~/.bashrc

配置文件 ~/.bashrc

# added by Anaconda3 installer
export PATH="/home/anaconda3/bin:$PATH"

https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ https://mirrors.aliyun.com/pypi/simple/tensorflow-gpu/

eustomaqua commented 6 months ago

实验环境 Python 3.8 miniconda3

# conda create -n enspi python=3.8
# source activate enspi
# pip list
# pip install -r requirements.txt
# python -m pytest tests/fair/test_manf_exp2.py

Docker 本地镜像

$ docker images
$ docker ps -a
$ docker commit <container-id> myexpt:init  #fairubuntu
$ docker save -o myexpt.tar myexpt

退出后重新进入

# exit
$ docker run -it myexpt:init /bin/bash
$ docker exec -it myexpt:init /bin/bash
$ cd /home
$ source activate enspi

https://zhuanlan.zhihu.com/p/348849578 如果想直接推去自己hub管理,镜像名改为your-hubname/mssql-2019-with-cimb:1.0 image vs. container cf1, cf2, cf3, cf4 fairgbm issue suggestion, docker-hub

eustomaqua commented 6 months ago

镜像制作 (Mac) Dockerfile

# 设置基础映像
FROM --platform=linux/amd64 ubuntu:latest

# 安装Miniconda
RUN apt-get update && apt-get install -y wget
RUN apt-get update && apt-get install vim -y

本地机

$ # 进入目录
$ cd ~  # locate Dockerfile

$ #编译镜像(默认为latest)(注意结尾一定要加.)
$ docker build -t fairgbm .
$ #编译指定版本镜像(注意结尾一定要加.)
$ docker build -t fairgbm:1.0 .

$ # 查看本地镜像 镜像列表
$ docker images

环境配置 见下 文件传递

$ cd ~/Desktop
$ docker cp Miniconda3-py311_24.1.2-0-Linux-x86_64.sh <container-id>:/home
$ docker cp Miniconda3-py311_24.1.2-0-Linux-aarch64.sh <container-id>:/home
$ # docker run -it ubuntu

$ docker start <container-id>
$ docker rename <container-old-name> <new-name>
$ docker [stop][start] <container-id>  # 启动/停止

镜像备份 (Mac)

eustomaqua commented 6 months ago

环境配置 cont. 容器内安装

# apt-get update
# apt install vim
# apt install wget

# apt-get clean
# apt-get autoremove

# cd home && ls

# bash ./Miniconda3-py311_24.1.2-0-Linux-x86_64.sh
# bash ./Miniconda3-py311_24.1.2-0-Linux-aarch64.sh
# rm Miniconda3-py311_24.1.2-0-Linux-x86_64.sh

Do you accept the license terms? [yes|no]
>>> yes
Miniconda3 will now be installed into this location:
[/root/miniconda3] >>> /home/miniconda3
Do you wish to update your shell profile to automatically initialize conda?
This will activate conda on startup and change the command prompt when activated.
If you'd prefer that conda's base environment not be activated on startup,
   run the following command when conda is activated:
conda config --set auto_activate_base false
You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>> no

配置运行环境

$ vim ~/.bashrc

# self-added by Anaconda3 installer
export PATH=/home/miniconda3/bin:$PATH

$ source ~/.bashrc
$ conda env list
$ conda create -n ensem python=3.8

其他 一些错误 Docker Error response from daemon, run -it-d 区别 run vs start,

下载文件 Miniconda3 Latest installer links by Python version, hash information Anaconda3 Installing previous versions, All package lists

eustomaqua commented 5 months ago

容器使用 启动和暂停

$ docker ps -a

$ docker stop <container-id>
$ docker start <container-id>

$ docker exec -it <container-id> /bin/bash
root@<container-id>:/# exit

资源占用查询

$ docker stats --no-stream

查看 docker 容器使用的资源