術語
鏡像:系統配置清單,用來創造容器,相當于菜譜
容器:是鏡像的實現,相當于照著菜譜做菜。
docker 鏡像源
- 改json 新版的 Docker 使用 /etc/docker/daemon.json(Linux) 或者%programdata%\docker\config\daemon.json(Windows) 來配置 Daemon。
請在該配置文件中加入(沒有該文件的話,請先建一個):
ustc "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
163 http://hub-mirror.c.163.com
中國官方 https://registry.docker-cn.com
- -registry-mirror參數
docker run hello-world --registry-mirror=https://docker.mirrors.ustc.edu.cn
- 修改/etc/default/docker
mirror=https://docker.mirrors.ustc.edu.cn"
從Docker registry 拉取鏡像
alpine 是鏡像名稱,是一個輕量級的linux 發行版
docker image pull alpine
下面一條命令顯示本地的鏡像
docker image ls
運行container
docker container run 鏡像名 運行的命令
-it 可以保持container 不退出,進行交互。
docker container run -it alpine /bin/sh
列出正在運行的container,如果加上-a則是全部的(包括已經停止的)container
docker container ls
docker container ls -a
新建自定義docker鏡像
docker build -t tutorial -f ./dockerfile.txt ./
從鏡像創建和運行容器
docker run -it --name container1 --net=host -v E:/docker/:/ds tutorial
簡單鏡像文件
# reference: https://hub.docker.com/_/ubuntu/
FROM ubuntu:16.04
# Adds metadata to the image as a key value pair example LABEL version="1.0"
LABEL maintainer="Hamel Husain <www.github.com/hamelsmu>"
##Set environment variables
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN apt-get update --fix-missing && apt-get install -y wget bzip2 ca-certificates \
build-essential \
byobu \
curl \
git-core \
htop \
pkg-config \
python3-dev \
python3-pip \
python-setuptools \
python-virtualenv \
unzip \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN echo 'export PATH=/opt/conda/bin:$PATH' > /etc/profile.d/conda.sh && \
wget --quiet https://repo.continuum.io/archive/Anaconda3-5.0.0.1-Linux-x86_64.sh -O ~/anaconda.sh && \
/bin/bash ~/anaconda.sh -b -p /opt/conda && \
rm ~/anaconda.sh
ENV PATH /opt/conda/bin:$PATH
RUN pip3 --no-cache-dir install --upgrade \
altair \
sklearn-pandas
# Open Ports for Jupyter
EXPOSE 7745
#Setup File System
RUN mkdir ds
ENV HOME=/ds
ENV SHELL=/bin/bash
VOLUME /ds
WORKDIR /ds
ADD run_jupyter.sh /ds/run_jupyter.sh
RUN chmod +x /ds/run_jupyter.sh
# Run the shell
CMD ["./run_jupyter.sh"]