Docker
FROM ubuntu
RUN apt update
RUN apt install -y wget bzip2
WORKDIR /opt
RUN wget -O Mambaforge.sh "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-$(uname)-$(uname -m).sh" -O Mambaforge.sh
RUN bash Mambaforge.sh -b -p /opt/miniconda
ENV PATH="/opt/miniconda/bin:$PATH"
#add channels
RUN conda config --add channels defaults
RUN conda config --add channels bioconda
RUN conda config --add channels conda-forge
# install dependencies
# RUN apt-get --yes install default-jre
RUN mamba install -c bioconda trimmomatic vsearch bedtools bowtie2 samtools diamond -y
- https://quay.io/
docker容器内⽆法ping通外部⽹络的解决办法
重新安装了docker之后,发现启动容器ping不通外⽹以及公司内部的虚拟机。
重新装⼀下docker的⽹卡之后顺利解决
#停⽌docker
systemctl stop docker
#docker0
ip link set dev docker0 down
#删除docker0⽹桥
brctl delbr docker0
#新增⼀个docker0⽹桥
brctl addbr docker0
#增加⽹卡(这⾥ip也完全使⽤这个)
ip addr add 172.16.10.0/24 dev docker0
#启⽤⽹卡
ip link set dev docker0 up
#重启docker服务
systemctl restart docker
Relocating the Docker root directory
https://www.ibm.com/docs/en/z-logdata-analytics/5.1.0?topic=compose-relocating-docker-root-directory\
sudo systemctl stop docker
sudo systemctl stop docker.socket
sudo systemctl stop containerd
sudo mv /var/lib/docker /new_dir_structure
sudo vim /etc/docker/daemon.json
{
"data-root": "/new_dir_structure/docker"
}
sudo systemctl start docker
docker info -f '{{ .DockerRootDir}}'
docker修改hostname
docker run -itd --network net1 --hostname host1 --name test yourimage
docker run -itd --network net1 --add-host=host1:172.18.0.3 --name test yourimage
# docker-compose.yml
extra_hosts:
- "host1:172.18.0.3"
- "host2:172.18.0.4"
网络管理
连接容器到指定网段
docker network connect bridge gitea
查看容器连接的网络
docker inspect 025
"Networks": {
"bridge": {
"IPAMConfig": {},
"Links": null,
"Aliases": [],
"NetworkID": "71c6e7141e4b0848662803e8b2e0c83e1a6ee878cfe2f08161b248f5afee6d7f",
"EndpointID": "89dbee18d16739d241a31f45681ad5f696d7198a983f2a3a5e610b56807c85ab",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.4",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:04",
"DriverOpts": {}
},
"gitea_gitea": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"server",
"0251c4e5f7e1"
],
"NetworkID": "8d9e760814751086379bd8754b5434fbacd2f693b1af31a23699bb847c619c86",
"EndpointID": "199aa7d4df631da4444d98632e188388051b1c5f480cdfeedb9e9b0d61cb2b27",
"Gateway": "172.24.0.1",
"IPAddress": "172.24.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:18:00:02",
"DriverOpts": null
}
}
容器管理
sudo docker ps
docker stop amazing_cori
docker logs amazing_cori
docker ps -a
docker start b750bbbcfd88
docker exec -it <mycontainer> bash
into docker container's shell
export container
docker ps -a
docker export 4cc8248434a1 > hello-world.tar
import container
docker import - new_hello_ward < hello-world.tar
docker images
镜像管理
sudo docker images
查看镜像
docker run -t -i ubuntu:15.10 /bin/bash
docker start container_id && docker exec -it container_id bash
使用版本为15.10的ubuntu系统镜像来运行容器
docker run httpd
获取镜像
docker run httpd
运行镜像
docker search httpd
查找镜像
docker rmi hello-world
删除镜像
docker build -t some-content-nginx .
构建镜像
dcoker info
docker镜像存储位置
save image
dcoker images
docker save e0408b4b2f86 > new_hello_ward.tar
load image
docker load < new_hello_ward.tar
The difference between save laod and export import
- export 导出的镜像文件体积小于 save 保存的镜像
- docker import 可以为镜像指定新名称,docker load 不能对载入的镜像重命名
- docker save 支持多个镜像打包到同一文件,docker export不支持
- export 导出(import 导入)是根据容器拿到的镜像,再导入时会丢失镜像所有的历史记录和元数据信息(即仅保存容器当时的快照状态),所以无法进行回滚操作。而 save 保存(load 加载)的镜像,没有丢失镜像的历史,可以回滚到之前的层(layer)
- docker export 的应用场景:主要用来制作基础镜像,比如我们从一个 ubuntu 镜像启动一个容器,然后安装一些软件和进行一些设置后,使用 docker export 保存为一个基础镜像。然后,把这个镜像分发给其他人使用,比如作为基础的开发环境。
- docker save 的应用场景:如果我们的应用是使用 docker-compose.yml 编排的多个镜像组合,但我们要部署的客户服务器并不能连外网。这时就可以使用 docker save 将用到的镜像打个包,然后拷贝到客户服务器上使用 docker load 载入。
运行nginx
sudo docker run --name webserver -d -p 81:80 nginx
docker exec -it webserver bash
echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html
exit
repository
https://cloud.sylabs.io/library
https://hub.docker.com/
https://biocontainers.pro/
https://quay.io/
Compose
/var/lib/docker/volumes/cbioportal-docker-compose_cbioportal_mysql_data/_data
cbioportal-session-database:
restart: unless-stopped
image: mongo:3.7.9
container_name: cbioportal-session-database-container
environment:
MONGO_INITDB_DATABASE: session_service
volumes:
- cbioportal_mongo_data:/data/db
networks:
- cbio-net
cbioportal-database:
restart: unless-stopped
image: mysql:5.7
container_name: cbioportal-database-container
environment:
MYSQL_DATABASE: cbioportal
MYSQL_USER: cbio_user
MYSQL_PASSWORD: somepassword
MYSQL_ROOT_PASSWORD: somepassword
volumes:
- ./data/cgds.sql:/docker-entrypoint-initdb.d/cgds.sql:ro
- ./data/seed.sql.gz:/docker-entrypoint-initdb.d/seed.sql.gz:ro
- cbioportal_mysql_data:/var/lib/mysql
networks:
- cbio-net
networks:
cbio-net:
volumes:
cbioportal_mysql_data:
cbioportal_mongo_data:
docker-compose exec cbioportal-database \
sh -c 'mysql -hcbioportal-database -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE"'
主机访问容器数据库
sudo docker-compose run -d -p 3307:3306 --name cbioportal-database cbioportal-database
批量删除
docker删除所有未使用的镜像
docker image prune
docker删除所有未使用的容器(删除所有处于非运行状态的容器)
docker container prune
docker删除所有未使用的网络
docker network prune
国内镜像
创建或修改 /etc/docker/daemon.json 文件,修改为如下形式
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]
}
docker 容器运行后不退出
docker run -d configserver tail -f /dev/null
或者
docker run -d configserver /bin/bash ping 127.0.0.1
或者
docker run -d configserver /bin/bash -c "while true;do echo hello docker;sleep 1;done"
参考
https://docs.docker.com/engine/install/ubuntu/
https://www.runoob.com/docker/docker-dockerfile.html
https://blog.csdn.net/y472360651/article/details/81289128
https://github.com/cBioPortal/cbioportal-docker-compose
mysql数据备份
https://jingyan.baidu.com/article/0eb457e55f33fc42f1a905b6.html
在 Docker 容器中运行 GATK
Singularity
Docker vs. Singularity for data processing: UIDs and filesystem access