Customizing and Building Containers



environment.yml file| Task | Command |
|---|---|
| Create a new conda environment | conda create -n <env_name> |
| Create with specific Python version | conda create --name <env_name> python=3.11 |
| Create with packages | conda create --name <env_name> numpy pandas |
| List all conda environments | conda env list or conda info --envs |
| Activate a conda environment | conda activate <env_name> |
| Deactivate a conda environment | conda deactivate |
| Remove a conda environment | conda env remove -n <env_name> |
| List all packages in environment | conda list |
| Remove a package from current environment | conda remove <package_name> |
| Task | Command |
|---|---|
| Update a package in current environment | conda update <package_name> |
| Remove a package in other environment | conda remove -n <env_name> <package_name> |
| Update a package in other environment | conda update -n <env_name> <package_name> |
| Update all packages in current environment | conda update --all |
| Share environment | conda env export --from-history > environment.yml |
Create conda environment from environment.yml |
conda env create --file environment.yml |
| Duplicate a conda environment | conda create --name <new_env> --clone <old_env> |
--name and -n are equivalent.--file and -f are equivalent.-p and --platform are equivalent, to specify the platform (e.g., linux-64, osx-arm64, win-64).๐ What are the commands for the following tasks?
| Command | Output |
|---|---|
#General file all platforms conda-lock lock --file environment.yml |
conda-lock.yml |
#General file for one platform (e.g., Linux) conda-lock lock --file environment.yml -p linux-64 |
conda-lock.yml |
#Explicit lock file for one platform (e.g., Linux) conda-lock -k explicit --file environment.yml -p linux-64 |
conda-linux-64.lock |
#Explicit lock file from conda-lock.yml conda-lock render -p linux-64 |
conda-linux-64.lock |
conda-lock.yml VS conda-linux-64.lock?| Feature | conda-lock.yml |
conda-linux-64.lock |
|---|---|---|
| Format | Unified YAML (multi-platform) | Explicit (single-platform) |
| Content | Structured metadata + dependencies for all platforms | Simple list of package URLs |
| File Size | Larger (contains all platforms) | Smaller (one platform only) |
| Installation | conda-lock install --name <env_name> conda-lock.yml |
conda create --name <env_name> --file conda-linux-64.lock |
| Use case | Development across multiple platforms | Production deployment, Docker, single platform |
| Speed | Slightly slower (conda-lock processes it) | Fastest |
.yml or .yaml) files for data storage and system configurations (NOT for documentation)
# for commentslatest for the image, use the specific version tag instead.
Source: Minions movie
docker-compose.yml file comes to the rescue!docker-compose.yml?docker compose upCntrl + C in the terminal where you launched the container, and then type docker-compose rmrenv: docker-renvdocker-compose.yml filedocker-compose.yml practiceStep-by-step instructions:
# 1. Please first `cd` to a local folder of your choice, don't put all files in your home directory!
# Example `cd` command:
cd /Users/skysheng/Desktop/github/dsci522
# 2. make a new folder called `demo_docker` (or any other name you like)
mkdir demo_docker
# 3. move into that folder we just created
cd demo_docker
# 4. create a docker-copose.yml file using nano
nano docker-compose.ymldocker-compose.yml practicedocker-compose.yml file. Local port is set at 8789, password is set to password, username is rstudio.services:
analysis-env:
image: rocker/rstudio:4.4.2
ports:
- "8789:8787"
volumes:
- .:/home/rstudio/project
environment:
PASSWORD: password
deploy:
resources:
limits:
memory: 5Gnano to create this file, you need to press Cntrl + X to attempt exit, by default it will ask you to save the file. Press Y and then press Enter to save the file.docker-compose.yml practice# 6. Print out the content of the file to make sure it is correct.
cat docker-compose.yml
# 7. Launch the container using docker compose files.
docker compose upAfter the container is launched, your terminal will be hanging. You can open your browser and go to http://localhost:8789 to access RStudio.
To stop the container, you need to type Cntrl + C in the terminal where you launched the container, and then type:
DockerfileDockerfile practiceStep-by-step instructions:
# 1. Please first `cd` to a local folder of your choice, don't put all files in your home directory!
# Example `cd` command:
cd /Users/skysheng/Desktop/github/dsci522
# 2. make a new folder called `demo_docker` (or any other name you like)
mkdir demo_docker
# 3. move into that folder we just created
cd demo_docker
# 4. create a environment.yml file using nano
nano environment.ymlDockerfile practiceenvironment.yml file.name: my_env
channels:
- conda-forge
dependencies:
- conda-lock=3.0.4
- pandas=2.3.3
- pandera=0.26.1
- pip=25.3
- python=3.11.14
- pip:
- deepchecks==0.19.1nano to create this file, you need to press Cntrl + X to attempt exit, by default it will ask you to save the file. Press Y and then press Enter to save the file.Dockerfile practiceDockerfile practiceDockerfile practiceDockerfile file. We use jupyter minimal notebook image as an example, and copy the conda-lock file to the container.FROM quay.io/jupyter/minimal-notebook:afe30f0c9ad8
COPY conda-linux-aarch64.lock /tmp/conda-linux-aarch64.lockDockerfile practiceDockerfile practice