Docker commonly used commands and Dockerfile

Docker Profile

The official explanation is: Docker is an application container engine open source, so developers can package their applications and dependencies into a portable mirror, and then publish to any of the popular Linux or Windows machine, can be virtualized . The container is full use of the sandbox mechanism will not have any interface with each other.
I understand: a lightweight virtual machine.

installation

Reference officer Networks https://docs.docker.com/install/

Docker commonly used commands

  • docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

    OPTIONS Description
    -d background
    -it foreground
    --rm exit delete container
    --name container name, for example: - name the Test
    -e set environment variables, for example: -e PASSWORD = "password"
    -v set volume mapping relationship, For example: -v / Data: / Data
    -p setting port mapping relationship, [host port]: [vessel port], e.g. :-p 8080: 8080

  • docker rm [CONTAINER] Delete container, you can specify name, or id
  • docker rm -f $(docker ps -aq) Forced to remove all containers
  • docker images See all mirrors
  • docker exec -it [CONTAINER] [COMMAND] Runs the specified command in the specified container
  • docker build .According to the current path Dockerfilegenerated image, you can now -fspecify the Dockerfilepath and -tname of the designated image

Use examples and explanations Dockerfile

FROM python:3.6 # 基础镜像,
ENV LANG C.UTF-8 # 设置环境变量, 也可以运行时 指定 -e
COPY pip.conf /root/.pip/pip.conf # 复制文件到路径中
ADD requirements.txt ./ # 同COPY相似,可自动进行解压操作
RUN pip install --upgrade pip && pip install -r requirements.txt # 运行的命令,构建依赖
WORKDIR /root/code # 设置工作路径,既默认路径
EXPOSE 80 443 # 指定暴露的端口,也可以运行时指定 -p
CMD ["python","manage.py","runserver"] # 容器运行时的默认指令

Guess you like

Origin www.cnblogs.com/yuzhenjie/p/11777571.html