Install CASM 0.3.x in a docker container
Running CASM in Docker Container
- The purpose of this note is to install CASM on some new Linux distributions where some old libraries are needed but don't exist
- Here we use
dockerto build the image because it is compatible with Vscode plugin for software development - Docker needs root privileges, we need to install a rootless version
Install Rootless version of Docker
- Run below will install docker in
${HOME}/bin
curl -fsSL https://get.docker.com/rootless | sh
- You also need to change
~/.bashrcas suggested by the output of the above script, shown below YOUR_USER_IDcan be obtained usingidYOUR_USER_NAMEis your username
export DOCKER_HOST=unix:///run/user/YOUR_USER_ID/docker.sock
export PATH=/home/YOUR_USER_NAME/bin:$PATH
- Then you need to
source ~/.bashrc
Configure an image using a Dockerfile
- You can import
CASM 0.3.xdirectly from my Docker Hub channeldengzeyu/casm.0.3.x:latest - For the CASM with source code stored in
/app/CASMcode, you can pulldengzeyu/casm.0.3.x:latest-dev CASMsource code is in/app/CASMcodeandMinicondais installed in/opt/conda- The Dockerfile below will install
Miniconda 3, andCASM
Build a CASM image for development
- You can do development of
CASM, e.g. changing the source code, based on the version on my Docker Hub channel - Prepare a Dockerfile:
casm_dev.dockerfile
# syntax=docker/dockerfile:1
FROM dengzeyu/casm.0.3.x:latest
RUN apt-get update && \
apt-get install -y vim make gcc autoconf m4 bash-completion libtool pkg-config automake && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Make RUN commands use `bash --login`:
SHELL ["/bin/bash", "--login", "-c"]
# Install CASM dependencies
RUN conda activate casm_dev && conda remove casm casm-python casm-cpp --force
RUN git clone https://github.com/caneparesearch/CASMcode.git /app/CASMcode
WORKDIR /app/CASMcode
ENV CASM_DIRTY_IS_OK=1
RUN conda activate casm_dev && bash build.sh
RUN make install
RUN conda activate casm_dev && pip install python/casm && bash clean.sh && conda clean -a -y
WORKDIR /
- Build this image name as
casm_dev
docker build ./ -f casm_dev.dockerfile -t casm_dev
Development using VS Code
- Use
vscode-remoteandsshto a machine, you need to configure the machine in~/.ssh/config - Install
dockerin the remote machine - Start a container from an image
- Then right-click the container and use
Attach Visual Studio Codeto enter the container
Create a container
- More details can be found here: https://docs.docker.com/engine/reference/commandline/run/
- Every time you execute
docker runyou will create a new container -drun in detachable mode (background)-irun in interactive mode-tis related to pseudo-TTY--nameis the name of this container-vmount/home/jerryoutside the container to/home/jerryinside the containerdengzeyu/casm.0.3.x:latestis the image that we want to run--rmautomatically remove this container when it is stopped
docker run -itd -v /home/jerry:/home/jerry --name casm_dev_container dengzeyu/casm.0.3.x:latest
Run a command in container outside of container interactively
- Here I'm running
casm initcommand in a conda environmentcasm_devinside a containercasm_dev_containerin the current path outside of container:$PWD - The command works only when you type this in the shell interactively
docker exec -it -w $PWD casm_dev_container conda run -n casm_dev casm init
Run a command in container outside of container in a script
#!/bin/bash
CASM="docker exec -w $PWD casm_dev_container conda run -n casm_dev casm"
PYTHON="docker exec -w $PWD casm_dev_container conda run -n casm_dev python"
$CASM monte -s monte.json >> stdout.txt
$PYTHON ../../analysis.py